ファイルを暗号化するための暗号化ツールがあります。暗号化されたファイルを調べると、暗号化されたファイル内に .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) -コードはほとんど正常に動作していますが、実際のテキストを置き換える 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
注 - FILE CONTAIN には文字 a (HEX VALUE = 61) のみが含まれます。