Reputation: 10681
I am using AES 256 to encrypt/decrypt some plain text. But the algorithm uses only PKCS7 for padding, but I need to use PKCS5 to make it compatible to other platforms. How can I achieve this?
My source code is:
public string Encrypt(byte[] PlainTextBytes, byte[] KeyBytes, string InitialVector)
{
byte[] InitialVectorBytes = Encoding.UTF8.GetBytes(InitialVector);
RijndaelManaged SymmetricKey = new RijndaelManaged();
SymmetricKey.Mode = CipherMode.CBC;
SymmetricKey.Padding = PaddingMode.PKCS7;
ICryptoTransform Encryptor = SymmetricKey.CreateEncryptor(KeyBytes, InitialVectorBytes);
MemoryStream MemStream = new MemoryStream();
CryptoStream CryptoStream = new CryptoStream(MemStream, Encryptor, CryptoStreamMode.Write);
CryptoStream.Write(PlainTextBytes, 0, PlainTextBytes.Length);
CryptoStream.FlushFinalBlock();
byte[] CipherTextBytes = MemStream.ToArray();
MemStream.Close();
CryptoStream.Close();
return ByteToHexConversion(CipherTextBytes);
}
Upvotes: 2
Views: 4024
Reputation: 49629
PKCS#5-padding and PKCS#7-padding are different names for the same algorithm. It is also sometimes called PKCS-padding or RFC3852-padding.
Upvotes: 4