Skip to content

Instantly share code, notes, and snippets.

View Ad1n's full-sized avatar
♟️
Focusing

@ad1n0d1n Ad1n

♟️
Focusing
  • Kupibilet
  • UAE, Dubai
View GitHub Profile
@trojkac
trojkac / openssl_pkey_rsa_from_json_web_key.rb
Last active October 31, 2023 02:07
Getting OpenSSL::PKey::RSA from base64 encoded modulus and exponent in JSON Web Key format
e = "AQAB"
n = "lxrwmuYSAsTfn-lUu4goZSXBD9ackM9OJuwUVQHmbZo6GW4Fu_auUdN5zI7Y1dEDfgt7m7QXWbHuMD01HLnD4eRtY-RNwCWdjNfEaY_esUPY3OVMrNDI15Ns13xspWS3q-13kdGv9jHI28P87RvMpjz_JCpQ5IM44oSyRnYtVJO-320SB8E2Bw92pmrenbp67KRUzTEVfGU4-obP5RZ09OxvCr1io4KJvEOjDJuuoClF66AT72WymtoMdwzUmhINjR0XSqK6H0MdWsjw7ysyd_JhmqX5CAaT9Pgi0J8lU_pcl215oANqjy7Ob-VMhug9eGyxAWVfu_1u6QJKePlE-w"
decoded_exponent = Base64.urlsafe_decode64(e)
decoded_modulus = Base64.urlsafe_decode64(n)
e = OpenSSL::BN.new(decoded_exponent, 2)
n = OpenSSL::BN.new(decoded_modulus, 2)
OpenSSL::PKey::RSA.new.set_key(n, e, nil)
@wteuber
wteuber / encrypt_decrypt.rb
Last active April 30, 2025 19:20
Simply encrypt and decrypt Strings in Ruby.
require 'openssl'
class String
def encrypt(key)
cipher = OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt
cipher.key = Digest::SHA1.hexdigest key
s = cipher.update(self) + cipher.final
s.unpack('H*')[0].upcase
end