Skip to content

Instantly share code, notes, and snippets.

@dakatsuka
Created November 15, 2010 09:37
Show Gist options
  • Save dakatsuka/700209 to your computer and use it in GitHub Desktop.
Save dakatsuka/700209 to your computer and use it in GitHub Desktop.
暗号化・復号化
# 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