Skip to content

Instantly share code, notes, and snippets.

@nori3tsu
Last active December 24, 2015 01:49
Show Gist options
  • Save nori3tsu/6726476 to your computer and use it in GitHub Desktop.
Save nori3tsu/6726476 to your computer and use it in GitHub Desktop.
AES/ECB/PKCS5Padding
require 'openssl'
require 'base64'
class AESCipher
def initialize(key)
@key = key
end
def encrypt(text)
cipher = OpenSSL::Cipher.new("AES-128-ECB")
cipher.encrypt()
cipher.key = @key
enc = cipher.update(text)
enc << cipher.final()
Base64.encode64(enc)
end
def decrypt(text)
enc = Base64.decode64(text)
cipher = OpenSSL::Cipher.new("AES-128-ECB")
cipher.decrypt()
cipher.key = @key
cipher.update(enc) + cipher.final
end
end
if __FILE__ == $0
key="1234567890123456"
text = "nori3tsu"
chipher = AESCipher.new(key)
enctext = chipher.encrypt(text)
puts enctext
dectext = chipher.decrypt(enctext)
puts dectext
end
@mustafaozcaninfo
Copy link

Mustafa Özcan

Kişisel Blog makalelerimi SEO konusundaki deneyimleri paylaştığım blogum.Fırsatları ayağınıza getiren mustafa ozcan blog kişisel temalı yazılar ile gündemde yer alan güncel yazıları sizlere sunma fırsatı ile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment