Module: Hoodie::Crypto::String
- Defined in:
- lib/hoodie/utils/crypto.rb
Overview
Adds ‘encrypt` and `decrypt` methods to strings.
Instance Method Summary collapse
-
#decrypt(password = nil, salt = nil) ⇒ Object
Returns a new string containing the decrypted version of itself.
-
#encrypt(password = nil, salt = nil) ⇒ Object
Returns a new string containing the encrypted version of itself.
-
#random_binary(n_bytes) ⇒ Object
Generate a random binary string of
n_bytessize.
Instance Method Details
#decrypt(password = nil, salt = nil) ⇒ Object
Returns a new string containing the decrypted version of itself
82 83 84 |
# File 'lib/hoodie/utils/crypto.rb', line 82 def decrypt(password = nil, salt = nil) Hoodie::Crypto.decrypt(self, password, salt) end |
#encrypt(password = nil, salt = nil) ⇒ Object
Returns a new string containing the encrypted version of itself
76 77 78 |
# File 'lib/hoodie/utils/crypto.rb', line 76 def encrypt(password = nil, salt = nil) Hoodie::Crypto.encrypt(self, password, salt) end |
#random_binary(n_bytes) ⇒ Object
Generate a random binary string of n_bytes size.
88 89 90 91 |
# File 'lib/hoodie/utils/crypto.rb', line 88 def random_binary(n_bytes) #(Array.new(n_bytes) { rand(0x100) }).pack('c*') SecureRandom.random_bytes(64) end |