Created
November 15, 2010 09:37
-
-
Save dakatsuka/700209 to your computer and use it in GitHub Desktop.
暗号化・復号化
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require 'openssl' | |
def encrypt(str, secret) | |
enc = OpenSSL::Cipher::Cipher.new("AES-256-CBC") | |
enc.encrypt | |
enc.pkcs5_keyivgen(secret) | |
return (enc.update(str) + enc.final).unpack("H*").first.to_s | |
end | |
def decrypt(str, secret) | |
dec = OpenSSL::Cipher::Cipher.new("AES-256-CBC") | |
dec.decrypt | |
dec.pkcs5_keyivgen(secret) | |
return dec.update([str].pack("H*")) + dec.final | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment