我正在将一个用PHP编写的应用程序转换为Ruby。在加密密码时,PHP应用程序使用以下代码:
if($method == 2 && CRYPT_BLOWFISH) return crypt($pass, '$2a$07$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxx$');
我假设这是使用Blowfish实现。这里的x都是a-zA-Z0-9字符。
Ruby中的Blowfish实现使用以下语法(取自http://crypt.rubyforge.org/blowfish.html):
blowfish = Crypt::Blowfish.new("A key up to 56 bytes long")
plainBlock = "ABCD1234"
encryptedBlock = blowfish.encrypt_block(plainBlock)
我没有一个长度为56字节或更少的字符串,并且从PHP版本中也不清楚应该是什么。那么,我该如何编写一个Ruby函数来加密密码,以给出与PHP相同的结果?