使用 AES(http://rubygems.org/gems/aes) 加密
require 'aes'
@key="aee18b71a9c35809baa8aa8f61fe6d8e"
iv=AES.iv(:base_64)
#=>"C49NhRMGQczrZYW3KewUQg=="
@message="hello;world"
enc64 = AES.encrypt(@message, @key, {:iv => iv})
p enc64
#=>"C49NhRMGQczrZYW3KewUQg==$/oBI179r+7o6ceLfV2omJQ==" iv 和密文使用$符连接
<?php
$str="/oBI179r+7o6ceLfV2omJQ==";
$iv_dec="C49NhRMGQczrZYW3KewUQg==";
$key="aee18b71a9c35809baa8aa8f61fe6d8e";
$message=mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key,
$str, MCRYPT_MODE_CBC, $iv_dec);
?>
#PHP Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in /home/fan/rails/Test/aes2.php on line 7
#提示 IV的长度与块长度不一致。
怎么回事?ruby 下的字符长度与 php 怎么换算?(ruby 是没有字符长度多少比特这一说法的吧)
谢谢!