Encryption 如何使用命令行工具解密rijndael

Encryption 如何使用命令行工具解密rijndael,encryption,command-line,openssl,mcrypt,Encryption,Command Line,Openssl,Mcrypt,我有一个加密测量数据的第三方来源,这些数据经常更新,需要解密。我知道如何使用mcrypt库在perl或ruby中解密数据 为了便于文档编制和访问,我想记录如何使用命令行工具解密密文。我尝试过mcrypt和openssl命令行工具,但似乎无法使用命令行工具正确解密密文 数据在ecb模式下用rijndael-128加密。这超出了我的控制范围 给出以下最小示例: 加密数据以二进制形式存储在文件“/ciphertext”中。 密文是这些字节的序列:0xfb 0x0d 0xfb 0xa2 0xfc 0

我有一个加密测量数据的第三方来源,这些数据经常更新,需要解密。我知道如何使用mcrypt库在perl或ruby中解密数据

为了便于文档编制和访问,我想记录如何使用命令行工具解密密文。我尝试过mcrypt和openssl命令行工具,但似乎无法使用命令行工具正确解密密文

数据在ecb模式下用rijndael-128加密。这超出了我的控制范围

给出以下最小示例:

  • 加密数据以二进制形式存储在文件“/ciphertext”中。
    • 密文是这些字节的序列:0xfb 0x0d 0xfb 0xa2 0xfc 0x43 0x0a 0xe5 0xe8 0x8b 0x25 0xac 0x06 0x9c 0xdd 0x77
    • 例如,可以在bash中使用
      printf'\xfb\x0d\xfb\xa2\xfc\x43\x0a\xe5\xe8\x8b\x25\xac\x06\x9c\xdd\x77'>/tmp/ciphertext
  • 加密密钥是值为121的32个重复字节(在ASCII中为32个小写“y”)
我可以用mcrypt在ruby中解密密码文本,如下所示:

require "rubygems"
require "mcrypt"

key = "y"*32
ciphertext = IO.read("ciphertext", :encoding => "BINARY")
puts(Mcrypt.new("rijndael-128", :ecb, "y"*32).decrypt(ciphertext))
#!/usr/bin/perl
use Crypt::Rijndael;

my $key = ("y" x 32);
my $ciphertext;
open(my $fh, '<', "ciphertext") or die "cannot open ciphertext";
{
   local $/;
   $ciphertext = <$fh>;
};
my $cipher = Crypt::Rijndael->new($key, Crypt::Rijndael::MODE_ECB());
print($cipher->decrypt($ciphertext) . "\n");
在Perl中,如下所示:

require "rubygems"
require "mcrypt"

key = "y"*32
ciphertext = IO.read("ciphertext", :encoding => "BINARY")
puts(Mcrypt.new("rijndael-128", :ecb, "y"*32).decrypt(ciphertext))
#!/usr/bin/perl
use Crypt::Rijndael;

my $key = ("y" x 32);
my $ciphertext;
open(my $fh, '<', "ciphertext") or die "cannot open ciphertext";
{
   local $/;
   $ciphertext = <$fh>;
};
my $cipher = Crypt::Rijndael->new($key, Crypt::Rijndael::MODE_ECB());
print($cipher->decrypt($ciphertext) . "\n");

-a
选项告诉openssl密码是base64编码的。但这是错误的,事实上,它不是base64编码的。此外,由于加密时未使用填充,因此还需要指定
-nopad
选项

openssl aes-256-ecb -d -nopad -K 7979797979797979797979797979797979797979797979797979797979797979 -in ciphertext

-a
选项告诉openssl密码是base64编码的。但这是错误的,事实上,它不是base64编码的。此外,由于加密时未使用填充,因此还需要指定
-nopad
选项

openssl aes-256-ecb -d -nopad -K 7979797979797979797979797979797979797979797979797979797979797979 -in ciphertext

谢谢你的参与,发现并纠正了我的错误,非常好!谢谢你的参与,发现并纠正了我的错误,非常好!