Java中的非对称加密:如何避免同一短语产生不同的结果?
我知道非对称加密的一个特点是,如果你用公钥加密文本,你每次都会得到不同的结果。
有没有办法始终获得相同的结果(没有 RSA)?
示例代码:
PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(
new RSAPublicKeySpec(
new BigInteger("83087..."),
new BigInteger("65537")));
PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(
new RSAPrivateKeySpec(
new BigInteger("830874..."),
new BigInteger("514268...")));
Cipher cipher = Cipher.getInstance( "RSA" );
cipher.init( Cipher.ENCRYPT_MODE, publicKey );
cipher.doFinal( "test");
I know that one characteristic of asymetric encryption is, that if you encryt a text with the public key, you get each time different results.
Is there a way to get always the same result (without RSA)?
Sample-Code:
PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(
new RSAPublicKeySpec(
new BigInteger("83087..."),
new BigInteger("65537")));
PrivateKey privateKey = KeyFactory.getInstance("RSA").generatePrivate(
new RSAPrivateKeySpec(
new BigInteger("830874..."),
new BigInteger("514268...")));
Cipher cipher = Cipher.getInstance( "RSA" );
cipher.init( Cipher.ENCRYPT_MODE, publicKey );
cipher.doFinal( "test");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
良好的加密必须给出不同的结果,因为它可以更安全地隐藏信息。它隐藏了一个事实,即两个单独的密文的明文是相等的。这称为语义安全。
它是通过 http://en.wikipedia.org/wiki/Initialization_vector 实现的。
是的,当然,加密是非对称的。
A good encryption must give different results, as it hides information more securely. It hides a fact that a plain text for two separate cipher texts is equal. It's called semantic security.
It's achieved by http://en.wikipedia.org/wiki/Initialization_vector.
And yes, of course, the encryption is asymmetric.