Can someone guide me how to convert following Oracle PL/SQL code to C#, please?
declare
l_encrypted raw (100);
p_key raw (100);
p_plain raw(100);
l_mode number;
begin
l_mode := dbms_crypto.ENCRYPT_DES + dbms_crypto.CHAIN_CBC + dbms_crypto.PAD_PKCS5;
p_key := 'A217B5BEF1477D1A';
p_plain := '07253075';
l_encrypted := dbms_crypto.encrypt(UTL_I18N.STRING_TO_RAW(p_plain, 'AL32UTF8'), l_mode, p_key);
dbms_output.put_line(l_encrypted);
--outputs this value: E4624E16DB69451A14BE265CDCC5B0AB
end;
My C# code is:
byte[] value = Encoding.UTF8.GetBytes("07253075");
byte[] key = Encoding.UTF8.GetBytes("A217B5BEF1477D1A");
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider
{
Mode = CipherMode.CBC,
Padding = PaddingMode.PKCS7,
};
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(key, key), CryptoStreamMode.Write);
cryptoStream.Write(value, 0, value.Length);
cryptoStream.Close();
Byte[] encrypted = memoryStream.ToArray();
MessageBox.Show(string.Join(string.Empty, Array.ConvertAll(encrypted, b => b.ToString("X2"))));
However, it throws CryptographicException complaining of key size. I searched Internet and found out that key size for DES is 8 bytes, but how Oracle encrypted my text? And how can I change my code to get the same output as Oracle?