license 是通过私有加密的文件,下面程序是在程序中使用公钥解密,然后进行相应验证操作
require 'openssl' require "base64" require "json" keypath = "/usr/auth/pub_key.pem" aclpath = "/usr/auth/license.txt" #判断加密文件是否存在 if !File::exists?(keypath) or !File::exists?(aclpath) then puts "授权文件不存在" end #读取并解密文件 rsa_priv = OpenSSL::PKey::RSA.new(File.read(keypath)) buffer = rsa_priv.public_decrypt(Base64.decode64(File.read(aclpath))) #判断时间是否过期 if !buffer then puts '无效的授权文件' end #判断时间 license = JSON.parse(buffer); #读取内容并验证 puts license
作者:daos
链接:https://www.jianshu.com/p/e044d47384d5
點擊查看更多內(nèi)容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦