我正在尝试做一个示例应用程序,用于测试目的与其他人开发,并希望将加密字符串打印到屏幕上,并将其放回解密机制......我似乎不是找到这样做的方法...我已经尝试过 base64 并解压缩,感觉就是这样,但没有到达那里。
require 'openssl'
require 'base64'
def ask(prompt)
loop do
print prompt, ' '
$stdout.flush
s = gets
return s.chomp
end
end
def aes(m,k,t)
(aes = OpenSSL::Cipher::Cipher.new('aes-256-cbc').send(m)).key = Digest::SHA256.digest(k)
aes.update(t) << aes.final
end
def encrypt(key, text)
aes(:encrypt, key, text)
end
def decrypt(key, text)
aes(:decrypt, key, text)
end
def my_decrypt
@crypted = ask("Crypted data: ")
decrypted = decrypt("12345678911131511192123252729412",@crypted)
print decrypted
end
def my_encrypt
@decrypted = ask("Data to encrypt: ")
crypted = encrypt("12345678911131511192123252729412",@decrypted)
print crypted
end
option=ask("Option 1 - Encrypt, 2 decrypt")
case option
when "1" then my_encrypt
when "2" then my_decrypt
else print "Option not valid"
end
有人来救援吗?
谢谢