Ruby openssl 生成证书
程序员文章站
2022-07-08 19:25:55
...
require 'openssl'
key = OpenSSL::PKey::RSA.new(1024)
digest = OpenSSL::Digest::SHA1.new()
issu = sub = OpenSSL::X509::Name.new()
sub.add_entry('O', 'Organization')
sub.add_entry('OU', 'Project Implementation')
sub.add_entry('CN', 'Ruby OpenSSL')
cer = OpenSSL::X509::Certificate.new()
cer.not_before = Time.at(0)
cer.not_after = Time.at(0)
cer.public_key = key # <= 接受签署的公匙
cer.serial = 1
cer.issuer = issu
cer.subject = sub
cer.sign(key, digest) # <= 签署用的秘匙和哈希表函数
print cer.to_text
#补充:生成证书文件(Certificate.crt)
File.open("Certificate","w")<<cer
上一篇: jsp
下一篇: PTA疑难杂症!!!