Coldfusion Encryption and Perl Decryption

时间:2019-01-09 22:12:12

标签: perl encryption coldfusion

I have a situation where I need to encrypt content in Coldfusion and then decrypt in Perl. Here's a sample Coldfusion code:

<cfscript>
  input = "Amidst the roar of liberated Rome, Of nations freed, and the world overjoy'd";
  encryptionKey = "8kbD1Cf8TIMvm8SRxNNfaQ==";
  encryptedInput = encrypt( input, encryptionKey, "AES/ECB/PKCS5Padding", "hex" );
  writeOutput( "Encrypted Input: #encryptedInput# <br />" );
</cfscript>

This produces:

27B0F3EB1286FFB462BDD3F14F5A41724DF1ED888F1BEFA7174CA981C7898ED2EF841A15CDE4332D030818B9923A2DBA0C68C8352E128A0744DF5F9FA955D3C72469FEFDAE2120DE5D74319ED666DDD0 

And the Perl:

use 5.24.1;
use Crypt::ECB qw(encrypt_hex);

my $input = "Amidst the roar of liberated Rome, Of nations freed, and the world overjoy'd";
my $encryption_key = "8kbD1Cf8TIMvm8SRxNNfaQ==";
my $encrypted_input = encrypt_hex($encryption_key, 'Rijndael', $input);
say $encrypted_input;

This produces:

e220ff2efe5d41e92237622ba969f35158d20e2c9c44995d44136d928d517462980321d4d6193fe62dc942fd717128442972524207777366954e5ceb2d1812ac997e06767a27d6a0145176d717c3836b

Why is the encrypted content different? Does anyone have any insights into this?

1 个答案:

答案 0 :(得分:2)

您的加密密钥是base64编码的,但是Crypt::ECB需要一个原始字节字符串(不过文档中还不清楚)。

use Convert::Base64;
...

my $encryption_key = decode_base64("8kbD1Cf8TIMvm8SRxNNfaQ==");
...

新输出:

27b0f3eb1286ffb462bdd3f14f5a41724df1ed888f1befa7174ca981c7898ed2ef841a15cde4332d030818b9923a2dba0c68c8352e128a0744df5f9fa955d3c72469fefdae2120de5d74319ed666ddd0