这是我加密的PL / SQL代码:
declare
passphrase RAW(128) := UTL_RAW.CAST_TO_RAW('SECRET_KEY1111111');
plaintext RAW(128) := UTL_RAW.CAST_TO_RAW('5421123500005002');
cyphertext RAW(1024);
encdata RAW (2000);
begin
cyphertext := DBMS_OBFUSCATION_TOOLKIT.DES3Encrypt(input => plaintext,
key => passphrase);
dbms_output.put_line('Encrypted:' || cyphertext);
encdata:=dbms_obfuscation_toolkit.DES3Decrypt(input=>hextoraw(cyphertext),key=>passphrase);
dbms_output.put_line('Decrypted:' || utl_raw.cast_to_varchar2(HEXTORAW(encdata)));
end;
我的C#解密代码:
byte[] b = HexStringToByteArray("E98C498A316CBE3B6AE16A82A4BE2F0F");
TripleDES des = TripleDES.Create();
des.Key = Encoding.UTF8.GetBytes("SECRET_KEY1111111");
//des.Mode = CipherMode.CBC;
//des.Padding = PaddingMode.PKCS7;
des.IV = HexStringToByteArray("0123456789ABCDEF");
ICryptoTransform ct = des.CreateDecryptor();
byte[] output = ct.TransformFinalBlock(b, 0, b.Length);//***EXCEPTION ON THIS LINE***
Console.WriteLine(Encoding.UTF8.GetString(output));
Console.ReadLine();
public byte[] HexStringToByteArray(string Hex)
{
byte[] Bytes = new byte[Hex.Length / 2];
int[] HexValue = new int[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x08, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
for (int x = 0, i = 0; i < Hex.Length; i += 2, x += 1)
{
Bytes[x] = (byte)(HexValue[Char.ToUpper(Hex[i + 0]) - '0'] << 4 |
HexValue[Char.ToUpper(Hex[i + 1]) - '0']);
}
return Bytes;
}
PL / SQL结果在这里:
14:18:33 PL/SQL block executed
Encrypted:E98C498A316CBE3B6AE16A82A4BE2F0F
Decrypted:5421123500005002
14:18:33 **** SCRIPT ENDED 17.07.2017 14:18:33 ****
14:18:33 End Script Execution
在.NET方面,我总是得到一个例外。 未处理的类型&#39; System.Security.Cryptography.CryptographicException&#39;发生在mscorlib.dll中 其他信息:错误数据。
不允许使用DBMS_CRYPTO,因此我需要使用DBMS_OBFUSCATION_TOOLKIT。我不知道DBMS_OBFUSCATION_TOOLKIT.DES3Encrypt过程的默认属性是什么。对于IV属性,我应该使用&#34; 0123456789ABCDEF&#34;或&#34; C992C3154997E0FB&#34;?我该怎么办?我的问题在哪里?有什么建议? 感谢