class String
Public Instance Methods
decrypt(key = "Some random key")
click to toggle source
# File lib/ext/string.rb, line 24 def decrypt(key = "Some random key") blowfish = Kruptos::Blowfish.new(key) value = ::Base64.decode64(self) decryptedValue = "" ( chunk = value.slice!(0,8) decryptedValue += blowfish.decrypt_block(chunk) ) until value.empty? ( decryptedValue = decryptedValue.chomp("\012") ) until (decryptedValue[decryptedValue.length-1] != "\012") return decryptedValue end
encrypt(key = "Some random key")
click to toggle source
# File lib/ext/string.rb, line 6 def encrypt(key = "Some random key") blowfish = Kruptos::Blowfish.new(key) String val = self # pad the value to be 8 bytes aligned. (8-(val.length % 8)).times { val += "\012" } encodedString = Base64.encode64(val) encryptedValue = "" ( chunk = val.slice!(0,8) encryptedValue += blowfish.encrypt_block(chunk) ) until val.empty? return ::Base64.encode64(encryptedValue); end