如何仅使用预定义的加密密钥加密传递的参数并包含某种类型的 check_string(即 EPOCH 时间)。然后对salveapp中的参数进行解码,验证check_string(本例中为EPOCH时间)是否在一定范围内或一定值。
这是一个简单的 ruby 示例,它在一个文件中,因此您需要对其进行修改以处理命令行参数等。
require 'openssl'
require 'digest/sha1'
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
c.encrypt
# your pass is what is used to encrypt/decrypt
c.key = key = Digest::SHA1.hexdigest("1094whfiubf9qwer8y32908u3209fn2032")
c.iv = iv = c.random_iv
e = c.update("#{Time.now.to_i}")
e << c.final
puts "encrypted: #{e}\n"
#sleep(15) #if you uncomment this the validation will fail.
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
c.decrypt
c.key = key
c.iv = iv
d = c.update(e)
d << c.final
if(Time.now.to_i - d.to_i < 10)
puts "decrypted: #{d}\n"
puts "Validated EPOCH Time"
else
puts "Validation FAILED."
end