Question

I need to do the triple DES encryption and decryption in ruby. Whether I can use openpgp gem Or any other dedicated gem is there for doing the triple DES encryption /decryption. Please suggest me .

Thanks

Was it helpful?

Solution

You're probably thinking of openssl, not openpgp. Here's a documentation of openssl encryption functions in ruby. You can also use the much simpler gibberish module. You need Ruby compiled with openssl support either way; either compile it yourself or find one available for download.

OTHER TIPS

If it absolutely has to be Triple DES, here's how you would obtain an instance with the OpenSSL extension:

cipher = OpenSSL::Cipher::Cipher.new("des-ede-cbc")
cipher.encrypt
key = cipher.random_key
iv = cipher.random_iv
...

Please ensure to call random_key and random_iv as illustrated here and in the docs that SilverbackNet already mentioned. In there, you will also find an example on how to do the actual encryption and decryption.

If you are free to choose the algorithm, you might want to choose AES over Triple DES, it's a lot faster and generally considered a more modern cipher.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top