【发布时间】:2016-08-17 14:49:58
【问题描述】:
我想加密一个字符串,以便最终用户可以验证它是由我加密的,但他们不能自己加密它。
例如,我有一个私钥“private”,一个公钥“public”,一条消息“hello world”,并且想要执行以下操作:
private_key = 'private'
public_key = 'public'
message = 'hello world'
encrypted_value = Crypto.encrypt(message, private_key)
# encrypted_value is now 'd92a01df241a3'
is_verified = Crypto.verify(message, public_key)
# given just the public key and the message, is_verified will
# be able to tell whether it's accurate
# note that the encrypted_value cannot be generated by just the public_key
# but it can be verified by the public_key
【问题讨论】:
-
你的意思可能是
is_verified = Crypto.verify(encrypted_value, public_key)?
标签: ruby ssl encryption cryptography pki