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
require 'openssl' | |
require 'base64' | |
rsa = OpenSSL::PKey::RSA.new(2048) | |
modulus = rsa.n | |
exponent = rsa.e | |
oid = OpenSSL::ASN1::ObjectId.new("rsaEncryption") | |
alg_id = OpenSSL::ASN1::Sequence.new([oid, OpenSSL::ASN1::Null.new(nil)]) | |
ary = [OpenSSL::ASN1::Integer.new(modulus), OpenSSL::ASN1::Integer.new(exponent)] |
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
p ="password" | |
#according to PKCS#5, should be at least 8 bytes. Public information, can be stored along with the pwd. | |
s = OpenSSL::Random.random_bytes(16) | |
c = 20000 # varies depending on how fast the system is, tweak until it takes "long enough" | |
digest = OpenSSL::Digest::SHA256.new | |
#should be >= the output size of the underlying hash function, but ">" doesn't improve security (says PKCS#5) | |
dk_len = digest.digest_length | |
#store the result for new passwords | |
value = OpenSSL::PKCS5.pbkdf2_hmac(p, s, c, dk_len, digest) |
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
require 'socket' | |
require 'openssl' | |
class MyServer | |
DHParam = OpenSSL::PKey::DH.new(128) | |
TEST_KEY_RSA1024 = OpenSSL::PKey::RSA.new <<-_end_of_pem_ | |
-----BEGIN RSA PRIVATE KEY----- | |
MIICXgIBAAKBgQDLwsSw1ECnPtT+PkOgHhcGA71nwC2/nL85VBGnRqDxOqjVh7Cx |
NewerOlder