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
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦