首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

Ruby openssl 生成证件

2012-11-05 
Ruby openssl 生成证书require opensslkey OpenSSL::PKey::RSA.new(1024)digest OpenSSL::Digest::S

Ruby openssl 生成证书

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 = 1cer.issuer = issucer.subject = subcer.sign(key, digest) # <= 签署用的秘匙和哈希表函数print cer.to_text#补充:生成证书文件(Certificate.crt)File.open("Certificate","w")<<cer

热点排行