如何在 C# 中使用 AES 加密然后在 Perl 中解密?
这是我的 C# 代码。我怎样才能用 Perl 解密这个?或者由于 OpenSSL,我无法在 Perl 中解密它?
RijndaelManaged RijndaelAlg = new RijndaelManaged();
FileStream fStream = File.Open(FileName, FileMode.OpenOrCreate);
byte[] initVectorBytes = Encoding.ASCII.GetBytes("11B2c3D4e5F6g7H8");
RijndaelAlg.IV = initVectorBytes;
string password = "11111111";
Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(password, Encoding.ASCII.GetBytes("22222222"));
RijndaelAlg.Key = key.GetBytes(RijndaelAlg.KeySize / 8);
fStream = File.Open(FileName, FileMode.OpenOrCreate);
cStream = new CryptoStream(fStream, RijndaelAlg.CreateEncryptor(RijndaelAlg.Key, RijndaelAlg.IV), CryptoStreamMode.Write);
StreamWriter sWriter = new StreamWriter(cStream);
sWriter.Write(input);
sWriter.Close();
cStream.Close();
fStream.Close();
非常感谢。
Here is my C# code. How could I decrypt this in Perl? Or I cannot decypt it in Perl due to OpenSSL?
RijndaelManaged RijndaelAlg = new RijndaelManaged();
FileStream fStream = File.Open(FileName, FileMode.OpenOrCreate);
byte[] initVectorBytes = Encoding.ASCII.GetBytes("11B2c3D4e5F6g7H8");
RijndaelAlg.IV = initVectorBytes;
string password = "11111111";
Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(password, Encoding.ASCII.GetBytes("22222222"));
RijndaelAlg.Key = key.GetBytes(RijndaelAlg.KeySize / 8);
fStream = File.Open(FileName, FileMode.OpenOrCreate);
cStream = new CryptoStream(fStream, RijndaelAlg.CreateEncryptor(RijndaelAlg.Key, RijndaelAlg.IV), CryptoStreamMode.Write);
StreamWriter sWriter = new StreamWriter(cStream);
sWriter.Write(input);
sWriter.Close();
cStream.Close();
fStream.Close();
Many Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下 Crypt::OpenSSL::AES。
当然,您的 Perl 代码需要以某种方式获得正确的密钥。
Take a look at Crypt::OpenSSL::AES.
Of course, your Perl code will need to get the right key somehow.
如果您使用 Rijndael/CBC,请使用 Crypt::Rijndael。或者更好地描述你的代码。
Use Crypt::Rijndael if you use Rijndael/CBC. Or better describe your code.