如何在android中使用带有签名的RSA来加密和解密消息

发布于 2024-10-16 09:42:14 字数 83 浏览 3 评论 0原文

没有密钥分发,用户将知道公钥和私钥(不会使用随机密钥生成器)。我必须用私钥加密散列消息才能提供签名 消息只有 10-20 个字符,因此系统可以尽可能简单

no key distribution, public and private keys will be known by users (random key generator will not be used). I have to encrypt hashed message with private key in order to provide signature
message will only 10-20 characters, so system can be as simple as it is possible

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾城°AllureLove 2024-10-23 09:42:14

为了生成数字签名,您不需要加密哈希值。签名是一个单独的加密原语;无论如何,哈希值都不是原始加密的,有一些填充。也就是说,代码是:

Signature Signer = Signature.getInstance("SHA1withRSA");
Signer.initSign(MyKey, new SecureRandom()); //Where do you get the key?
byte []Message = MyMessage(); //Initialize somehow
Signer.update(Message, 0, Message.length);
byte [] Signature = Sign.sign();

For generating a digital signature, you don't need to encrypt the hash. Signing is a separate crypto primitive; the hash is not encrypted raw anyway, there's some padding. That said, the code is:

Signature Signer = Signature.getInstance("SHA1withRSA");
Signer.initSign(MyKey, new SecureRandom()); //Where do you get the key?
byte []Message = MyMessage(); //Initialize somehow
Signer.update(Message, 0, Message.length);
byte [] Signature = Sign.sign();
失去的东西太少 2024-10-23 09:42:14

好的,回来告诉我们你想要什么。您是否试图通过保护消息内容来获取隐私,或者通过表明消息确实来自发件人来保证真实性

如果您正在寻求隐私,那么 RSA 不是最佳选择:使用 RSA 生成私有/公共对,然后使用它们交换密钥,或在带外交换密钥。使用 AES 等流式算法来加密消息。

如果您只想通过签名来显示该消息的始发者,请查看 Wiki关于数字签名的文章——相当简单。

Okay, back up and tell us what you want. Are you trying to get privacy by protecting the contents of the message, or guarantee authenticity by showing that the message really came from the originator?

If you're looking for privacy, RSA isn't the way to go: use RSA to generate a private/public pair, and then use them to excahnge keys -- or exchange keys out of band. Use a streaming algorithm like AES to encrypt the message.

If you just want signature to show the message was originated by who you think it was, then have a look at the Wiki article on digital signature -- it's reasonably straightforward.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文