Recent

Author Topic: Is there lib for rijndael256  (Read 966 times)

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Is there lib for rijndael256
« on: March 21, 2019, 08:27:03 am »
I am looking for lib that give me encryption Rijndeal256
DCP only provice Rijndeal128 with IV 128bit, what i need 256 with IV longer 512bit

IDK if AES 256 is same with Rijndeal256 (i am noob in that field)

This online example of what i need of iv=1b426c12fe61900dbd5c0eb5520eadaf6d710cc25ee89ecee759f43de5afb892

http://rijndael.online-domain-tools.com/run/?inputType=frm-text&text=test&text_type=plain&function=rijndael-256&mode=cbc&key=679c0eff6ddb701094c26735f1f057fc&key_type=plain&iv=1b426c12fe61900dbd5c0eb5520eadaf6d710cc25ee89ecee759f43de5afb892&do=form-submit&encrypt=do

My problem i need that to connect online api service i cant manage it to change to another encryption.

any idea

Thanks in advance

Thaddy

  • Hero Member
  • *****
  • Posts: 7798
Re: Is there lib for rijndael256
« Reply #1 on: March 21, 2019, 11:56:33 am »
I think our member Xor-el wrote such a beast....
Ad Brexinitum (can't help it)

Xor-el

  • Sr. Member
  • ****
  • Posts: 266
Re: Is there lib for rijndael256
« Reply #2 on: March 22, 2019, 03:27:01 am »
I am looking for lib that give me encryption Rijndeal256
DCP only provice Rijndeal128 with IV 128bit, what i need 256 with IV longer 512bit

IDK if AES 256 is same with Rijndeal256 (i am noob in that field)

This online example of what i need of iv=1b426c12fe61900dbd5c0eb5520eadaf6d710cc25ee89ecee759f43de5afb892

http://rijndael.online-domain-tools.com/run/?inputType=frm-text&text=test&text_type=plain&function=rijndael-256&mode=cbc&key=679c0eff6ddb701094c26735f1f057fc&key_type=plain&iv=1b426c12fe61900dbd5c0eb5520eadaf6d710cc25ee89ecee759f43de5afb892&do=form-submit&encrypt=do

My problem i need that to connect online api service i cant manage it to change to another encryption.

any idea

Thanks in advance

you cannot have an IV of 512 bits with a cipher of 256 bits (Rijndeal256) in CBC mode.
it is just not possible. according to CBC mode standards, the IV must must be same length as the cipher blocksize.

By the way, CryptoLib4Pascal has support for Rijndael256
« Last Edit: March 22, 2019, 03:38:23 am by Xor-el »

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: Is there lib for rijndael256
« Reply #3 on: March 22, 2019, 09:38:37 am »
I m not good at this field, but if you look at example (the link)

Key = 679c0eff6ddb701094c26735f1f057fc
it is 256 bit

IV = 1b426c12fe61900dbd5c0eb5520eadaf6d710cc25ee89ecee759f43de5afb892   
it s 512
Maybe it is special case for rijndeal256

Also i have working example in PHP, and C# not test for same key and IV

Xor-el

  • Sr. Member
  • ****
  • Posts: 266
Re: Is there lib for rijndael256
« Reply #4 on: March 22, 2019, 09:48:24 am »
I m not good at this field, but if you look at example (the link)

Key = 679c0eff6ddb701094c26735f1f057fc
it is 256 bit

IV = 1b426c12fe61900dbd5c0eb5520eadaf6d710cc25ee89ecee759f43de5afb892   
it s 512
Maybe it is special case for rijndeal256

Also i have working example in PHP, and C# not test for same key and IV

You say you have working sample for CSharp with 512 bits IV?
Can you post it?

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: Is there lib for rijndael256
« Reply #5 on: March 22, 2019, 09:58:02 am »
after i reviewed it, yes it is not 512, that site should be wrong
it is SHA256 and passed in PHP as binary not a string.

In C# same code as PHP

Code: [Select]

static byte[] Encrypt(string plainText) {
byte[] Key = md5(secret);
byte[] IV = Sha256(apikey);
// fix php weird string to bytearray conversion
Key = System.Text.Encoding.UTF8.GetBytes(BitConverter.ToString(Key).Replace("-", "").ToLower());
byte[] encrypted;
// Create an Rijndael object
// with the specified key and IV.
using(Rijndael rijAlg = Rijndael.Create()) {
rijAlg.BlockSize = IV.Length * 8;
rijAlg.KeySize = Key.Length * 8;
rijAlg.Padding = PaddingMode.Zeros;
rijAlg.Mode = CipherMode.CBC;
rijAlg.Key = Key;
rijAlg.IV = IV;
// Create a decrytor to perform the stream transform.
ICryptoTransform encryptor = rijAlg.CreateEncryptor(rijAlg.Key, rijAlg.IV);
// Create the streams used for encryption.
using(MemoryStream msEncrypt = new MemoryStream()) {
using(CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) {
using(StreamWriter swEncrypt = new StreamWriter(csEncrypt)) {
//Write all data to the stream.
swEncrypt.Write("encchk=1/" + plainText);
}
encrypted = msEncrypt.ToArray();
}
}
}
// Return the encrypted bytes from the memory stream.
return encrypted;
}



So yes you are right it is IV 256bit

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: Is there lib for rijndael256
« Reply #6 on: March 22, 2019, 10:01:10 am »
Now i need one for Pascal, same as C#
I looked at CryptoLib4Pascal but it is very complex to understand it for me.

Xor-el

  • Sr. Member
  • ****
  • Posts: 266
Re: Is there lib for rijndael256
« Reply #7 on: March 22, 2019, 10:11:55 am »
Now i need one for Pascal, same as C#
I looked at CryptoLib4Pascal but it is very complex to understand it for me.

Can you provide the plaintext, secret, apikey and output you expect so I can create a demo for you?

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: Is there lib for rijndael256
« Reply #8 on: March 22, 2019, 10:21:16 am »
This a real example

Code: [Select]
text = 'encchk=1/Param1=Abcd/ParamN=1234'

iv SHA256 in hex: 1b426c12fe61900dbd5c0eb5520eadaf6d710cc25ee89ecee759f43de5afb892
key is string: 679c0eff6ddb701094c26735f1f057fc
out in hex: 462bed108851c649247b16dc4258d47d4d6783489f96d8f7686a19529a4db3b3
final out in base64: RivtEIhRxkkkexbcQljUfU1ng0ifltj3aGoZUppNs7M

Xor-el

  • Sr. Member
  • ****
  • Posts: 266
Re: Is there lib for rijndael256
« Reply #9 on: March 22, 2019, 10:29:41 am »
This a real example

Code: [Select]
text = 'encchk=1/Param1=Abcd/ParamN=1234'

iv SHA256 in hex: 1b426c12fe61900dbd5c0eb5520eadaf6d710cc25ee89ecee759f43de5afb892
key is string: 679c0eff6ddb701094c26735f1f057fc
out in hex: 462bed108851c649247b16dc4258d47d4d6783489f96d8f7686a19529a4db3b3
final out in base64: RivtEIhRxkkkexbcQljUfU1ng0ifltj3aGoZUppNs7M
Ok, will create the demo when on PC.

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: Is there lib for rijndael256
« Reply #10 on: March 22, 2019, 11:48:29 am »

Xor-el

  • Sr. Member
  • ****
  • Posts: 266
Re: Is there lib for rijndael256
« Reply #11 on: March 22, 2019, 11:50:30 am »
Same i think because you lead a zeros

http://rijndael.online-domain-tools.com/link/1759f57gluVGkm3OiC/

the original implementation, what padding mode does it use?

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: Is there lib for rijndael256
« Reply #12 on: March 22, 2019, 11:53:58 am »
Not sure if Server will accepts padding zeros, i think not bad to try with it

Xor-el

  • Sr. Member
  • ****
  • Posts: 266
Re: Is there lib for rijndael256
« Reply #13 on: March 22, 2019, 12:01:57 pm »
Not sure if Server will accepts padding zeros, i think not bad to try with it

didn't your api specify what padding and block mode to use?

Zaher

  • Hero Member
  • *****
  • Posts: 571
    • parmaja.com
Re: Is there lib for rijndael256
« Reply #14 on: March 22, 2019, 12:41:07 pm »
Nothing in API PDF about padding, but it use CBC mode,
like in this somple php code

Code: [Select]
        $iv = hash("SHA256", $apikey, true);
        $key = md5($secret);
        $output = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $iv);
        return rtrim(strtr(base64_encode($output), '+/', '-_'), '=');