欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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
相关标签: Ruby

上一篇: jsp

下一篇: PTA疑难杂症!!!