问题
System.Security.Cryptography.TripleDES allow me use zero padding like this :
static TripleDES CreateTripleDES(byte[] key, byte[] iv)
{
TripleDES des = new TripleDESCryptoServiceProvider();
des.Key = key;
des.IV = iv;
des.Mode = CipherMode.CBC;
des.Padding = PaddingMode.Zeros;
return des;
}
Now change to use OpenSSL
CipherContext cc = new CipherContext(Cipher.DES_EDE3_CBC);
byte[] des3 = cc.Encrypt(msg2, tripleKey, tripleIv, 0);
//public byte[] Encrypt(byte[] input, byte[] key, byte[] iv, int padding);
The problem is that when i encrypt a string by two methods, i receive two diffences result :
first method (OK): 90dd67c475dc3a8ce3d0c8927ce43758715888c16688c9828ac92aa86019126297b7ccb80a4729224acd07285b85a847e48fb01b3da4639c
second method (NOT OK): 90dd67c475dc3a8ce3d0c8927ce43758715888c16688c9828ac92aa86019126297b7ccb80a4729224acd07285b85a847b77485eb0a1f214e
I guess that is because of the padding zero. But i don't know how to use padding zero in openssl.
Any help is appreciated.
回答1:
Openssl doesn't allow for "zero padding", probably because the result is not consistent (what if the last byte of plaintext is a 0...)
Openssl will let you use either PKCS padding or no padding (which requires the input to be a multiple of the block size in length).
If you want to emulate this "zero padding", you would need to append an appropriate amount of 0's yourself, and then choose the no padding option.
来源:https://stackoverflow.com/questions/6087155/use-zero-padding-in-openssl