在Ruby中实现PBEWithMD5AndDES [英] Implementation of PBEWithMD5AndDES in Ruby

查看:188
本文介绍了在Ruby中实现PBEWithMD5AndDES的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得一个加密lib的ruby实现,它显然是在Java世界中流行的 - PBEWithMD5AndDES

I'm trying to get a ruby implementation of an encryption lib that's apparently popular in the Java world -- PBEWithMD5AndDES

有人知道如何使用openssl或另一个开放源代码gem执行与此格式兼容的加密/解密?

Does anyone know how to use openssl or another open source gem to perform encryption/decryption that's compatible with this format?

更新:

我使用一个宝石 chilkat 来实现它,但它是付费的,我需要一个开源解决方案。

I used a gem chilkat to implement it but it is paid, i need an opensource solution.

推荐答案

我知道它是超老,但我有同样的问题,只是解决了,所以这里
加密,其中salt是你的盐,密钥是你的密码密钥字符串,迭代是你想使用的迭代次数

I know it is super old but I had the same problem and just solved it so here it goes to encrypt, where salt is your salt sting, passkey is your password key string and iterations is number of iterations you want to use

def encrypt_account_number
cipher = OpenSSL::Cipher::Cipher.new("DES")
cipher.encrypt
cipher.pkcs5_keyivgen passkey, salt,iterations,digest
encrypted_account_number =  cipher.update(account_number)
encrypted_account_number << cipher.final
Base64.encode64(encrypted_account_number )
end

def decrypt_account_number
cipher = OpenSSL::Cipher::Cipher.new("DES")
base_64_code = Base64.decode64(account_number)
cipher.decrypt
cipher.pkcs5_keyivgen passkey, salt,iterations,digest

decrypted_account_number = cipher.update base_64_code
decrypted_account_number << cipher.final
decrypted_account_number
end

这篇关于在Ruby中实现PBEWithMD5AndDES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆