我有一个加密工具对文件进行加密,当我研究加密文件时,发现它正在加密文件中写入.PEM的名称。
I found encryption logic is commonly used as below,
it supporting encryption of any file, it means RSA keys can not be use for encryption so here
it is creating a key(K) and encrypt it with RSA public key and then using key(K) for encrypting the file.我编写的C#代码如下,这是好的,但对于大文件是得到一些垃圾字符在中间喜欢,
aaaaaaaaaaaaaaaa
??M'yaaaaaaaaaa?我的解密码是:-
System.Security.Cryptography.TripleDESCryptoServiceProvider tripleDES = new System.Security.Cryptography.TripleDESCryptoServiceProvider();
tripleDES.Key = result; // 16 byte of key
tripleDES.Mode = System.Security.Cryptography.CipherMode.CBC;
byte[] IV = { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 };
tripleDES.IV = IV;
tripleDES.Padding = System.Security.Cryptography.PaddingMode.Zeros;
System.Security.Cryptography.ICryptoTransform cTransform = tripleDES.CreateDecryptor();
byte[] resultArray = cTransform.TransformFinalBlock(enc_data, 0, enc_data.Length);
//string s = Convert.ToBase64String(resultArray);
string x = System.Text.Encoding.ASCII.GetString(resultArray);
System.IO.File.WriteAllText(@"D:\570_f.txt", x);
tripleDES.Clear();1) -code几乎正常工作,但是在某个地方,发现了8字节的垃圾字符代替了真正的文本。
.................okokokookokok8bytejunkokokokokokokookko..............8bytjunkokokokokokokokokokoko............2)不知道加密过程中使用的填充方案是什么,我尝试了零填充模式下的解密。
----testing with different length file-----
(A)
input_file |encrypted_file with_tool | decrypted_file_with_above_code
10224 byte | x | 10232 byte
ok data + last 8 hex byte 3F 00 00 00 00 00 00 00
(b)
input_file |encrypted_file with_tool | decrypted_file_with_above_code
10242 byte | x | 10248 byte
ok data + last 8 hex byte 0D 3F 3F 3F 3C 56 31 65
(C)
input_file |encrypted_file with_tool | decrypted_file_with_above_code
10258 byte | x | 10264 byte
ok data + last 24 hex byte
0A 3F 3F 14 4D 27 79 0F 61 61 61 61 61 61 61 61
61 61 3F 00 00 00 00 00 注-文件只包含字符a (HEX值= 61),这里的任何建议都是很高兴听到的。
发布于 2016-12-20 19:18:45
最后发现这个加密工具是以n字节块的形式输入的。对于n字节块,不存在填充,而小于n字节的任何块被填充80,然后加上00使其为8的倍数。
我试图以同样的方式解密,以n字节块的形式分离完整的文件,然后解密每个块并将输出保存在一个缓冲区中,
最后将完整的缓冲区转换为字符串并粘贴到文件中。
https://stackoverflow.com/questions/41162511
复制相似问题