问题描述
我想要在不久之前看到在rails中解密和加密字符串的可能性,而不包括任何图书馆,但我找不到博客文章。能够加密和解密字符串而不包含任何东西。
使用相同的键对于rails中的所有其他内容,例如签名的Cookie。
任何想法?
你的意思是这个?:。这是重用Rails 4应用程序秘密的方法:
crypt = ActiveSupport :: MessageEncryptor.new(Rails.application.secrets。 secret_key_base)
encrypted_data = crypt.encrypt_and_sign('我的信心数据')
加密数据可以解密:
decryptpted_back = crypt.decrypt_and_verify(encrypted_data)
pre>
以前的Rails 3正在使用
secret_token
配置选项,加密方法是encrypt
decrypt
。
I saw a while ago the possibility to decrypt and encrypt strings in rails without including any library, but I can't find the blog post.
I want to be able to encrypt and decrypt strings without including anything. Using the same key has for the everything else in rails, signed cookies for example.
Any ideas?
解决方案You mean this one?: ActiveSupport::MessageEncryptor. Here is the way to reuse Rails 4 application's secret:
crypt = ActiveSupport::MessageEncryptor.new(Rails.application.secrets.secret_key_base) encrypted_data = crypt.encrypt_and_sign('my confidental data')
And encrypted data can be decrypted with:
decrypted_back = crypt.decrypt_and_verify(encrypted_data)
Previously Rails 3 was using
secret_token
configuration option and encryptor methods wereencrypt
decrypt
.这篇关于使用Rails加密,解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!