gpt4 book ai didi

java - 是否可以像在 Java 端那样使用模数和指数生成 RSA 私钥?

转载 作者:行者123 更新时间:2023-11-28 13:52:11 28 4
gpt4 key购买 nike

我在 iOS 解决方案上使用 RSA 解密。我想使用在 Java 端使用的相同参数来创建 privateKey,但我找不到方法。有没有办法做到这一点,或者是否可以使用 Java 导出此私钥,然后将其导入 iOS 解决方案?

byte[] modulusBytes = Base64.decode("base64EncodedString");
byte[] DBytes = Base64.decode("anotherBase64EncodedString");
BigInteger modulus = new BigInteger(1, modulusBytes );
BigInteger exponent = new BigInteger(1, DBytes);

RSAPrivateKeySpec rsaPrivKey = new RSAPrivateKeySpec(modulus, exponent);
KeyFactory fact = KeyFactory.getInstance("RSA");
PrivateKey privKey = fact.generatePrivate(rsaPrivKey);
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");

我的 iOS 应用程序将使用此算法解密 QRCode。 QRCode 通过如下公钥使用 Java 加密。为了解密这段代码,我们在 Java 端使用上面的代码。那么我们如何生成能够解密的相同私钥呢?如果没有相同的模数和指数,是否可以做到这一点?

byte[] modulusBytes = Base64.decode("base64EncodedString");

byte[] exponentBytes = Base64.decode("AQAB");
BigInteger modulus = new BigInteger(1, modulusBytes );
BigInteger exponent = new BigInteger(1, exponentBytes);

RSAPublicKeySpec rsaPubKey = new RSAPublicKeySpec(modulus, exponent);
KeyFactory fact = KeyFactory.getInstance("RSA");
PublicKey pubKey = fact.generatePublic(rsaPubKey);

最佳答案

这不是它应该的工作方式。您可以在每一方生成一对私钥和公钥,并交换公钥 key 。双方将使用对方的公钥加密他们希望发送的消息(前提是它们不太长),并使用自己的私钥解密收到的消息。但是私钥是并且应该保持私有(private)

关于java - 是否可以像在 Java 端那样使用模数和指数生成 RSA 私钥?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54407219/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com