[英]How DES oracle Decrypt equivalent in c#
I have this function on oracle db:我在 oracle 数据库上有这个 function:
BEGIN
key_raw := utl_i18n.string_to_raw(key,'AL32UTF8');
plaintext := dbms_crypto.decrypt(
src => chipertext,
typ => dbms_crypto.DES_CBC_PKCS5,
key => key_raw
);
return utl_i18n.raw_to_nchar(plaintext,'AL32UTF8');
END
and need to implement in c#.Net并且需要在 c#.Net 中实现
this what I've Done:这就是我所做的:
public static string DecryptDES(string strData,string skey)
{
byte[] clearData = Encoding.UTF8.GetBytes(strData);
byte[] key = Encoding.UTF8.GetBytes(skey);
DES desDecrypt = new DESCryptoServiceProvider();
desDecrypt.Mode = CipherMode.CBC;
desDecrypt.Padding = PaddingMode.PKCS7;
desDecrypt.Key = key;
ICryptoTransform transForm = desDecrypt.CreateDecryptor();
MemoryStream decryptedStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(decryptedStream, transForm, CryptoStreamMode.Write);
cryptoStream.Write(clearData, 0, clearData.Length);
cryptoStream.FlushFinalBlock();
byte[] plain = decryptedStream.ToArray();
return Encoding.UTF8.GetString(plain);
}
in oracle that function called like this:在 oracle 中,function 像这样调用:
select decrypt('BEB9B507432B91E116EC3F07364E38C5', 'testtesttest') from dual;
when this method call in c#:当此方法在 c# 中调用时:
DecryptDES("BEB9B507432B91E116EC3F07364E38C5", "testtesttest")
it's return error:这是返回错误:
System.ArgumentException: 'Specified key is not a valid size for this algorithm.'
also I tried another key and chipertext and it's return bad data.我也尝试了另一个密钥和chipertext,它返回了错误的数据。
I believe this is something to do with data format, since it's return error on c#, any suggestion?我相信这与数据格式有关,因为它在 c# 上返回错误,有什么建议吗?
What's wrong is that your ciphertext input in C# is a string.问题是您在 C# 中输入的密文是一个字符串。 Ciphertext (your
chipertext
, ugh) is binary (or "RAW" in Oracle speak).密文(你的
chipertext
,呃)是二进制的(或 Oracle 中的“RAW”)。 There should be no UTF-8 conversion to / from the ciphertext, because that may lead to missing data.应该没有 UTF-8 与密文之间的转换,因为这可能会导致数据丢失。
You'll probably have to use the first 7 or 8 bytes of the UTF-8 encoded key for DES.您可能必须为 DES 使用 UTF-8 编码密钥的前 7 或 8 个字节。 Yuk.
玉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.