使用ruby中的openpgp gem进行三层加密和解密

时间:2021-02-11 18:23:34

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 .

我需要在ruby中做三重DES加密和解密。我是否可以使用openpgp gem或任何其他专用的gem进行三重DES加密/解密。请建议我。

Thanks

谢谢

2 个解决方案

#1


4  

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.

您可能想到的是openssl,而不是openpgp。下面是ruby中openssl加密功能的文档。您还可以使用更简单的gibberish模块。无论哪种方式,都需要使用openssl支持编译的Ruby;可以自己编译,也可以下载。

#2


3  

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

如果它必须是三重DES,那么您可以通过OpenSSL扩展获得一个实例:

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.

请确保调用random_key和random_iv,如这里所示,以及SilverbackNet已经提到的文档中。在那里,您还将找到一个关于如何进行实际的加密和解密的示例。

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.

如果你可以*选择算法,你可能想要选择AES而不是三倍,它的速度更快,通常被认为是一个更现代的密码。

#1


4  

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.

您可能想到的是openssl,而不是openpgp。下面是ruby中openssl加密功能的文档。您还可以使用更简单的gibberish模块。无论哪种方式,都需要使用openssl支持编译的Ruby;可以自己编译,也可以下载。

#2


3  

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

如果它必须是三重DES,那么您可以通过OpenSSL扩展获得一个实例:

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.

请确保调用random_key和random_iv,如这里所示,以及SilverbackNet已经提到的文档中。在那里,您还将找到一个关于如何进行实际的加密和解密的示例。

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.

如果你可以*选择算法,你可能想要选择AES而不是三倍,它的速度更快,通常被认为是一个更现代的密码。