- 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")<
12-25 21:09