Skip to content

Instantly share code, notes, and snippets.

View leduytung's full-sized avatar

Lê Duy Tùng leduytung

  • Hà Nội, Việt Nam
View GitHub Profile
@leduytung
leduytung / encrypt_decrypt.rb
Created July 24, 2017 04:29 — forked from wteuber/encrypt_decrypt.rb
Simply encrypt and decrypt Strings in ruby.
require 'openssl'
class String
def encrypt(key)
cipher = OpenSSL::Cipher::Cipher.new('DES-EDE3-CBC').encrypt
cipher.key = Digest::SHA1.hexdigest key
s = cipher.update(self) + cipher.final
s.unpack('H*')[0].upcase
end