Java 中的 RSA:BigInteger 和 byte[]
RSA in Java: BigInteger and byte[]
我正在尝试在 Java 中编写 RSA 加密和解密函数,但遇到了一些麻烦:我认为是 BigInteger 和 byte[] 或反之亦然之间的转换引起的,有什么建议吗?
public byte[] encrypt(byte[] message, BigInteger n, BigInteger e) {
BigInteger m = new BigInteger(1, message);
BigInteger c = m.modPow(e, n);
return c.toByteArray();
}
public byte[] decrypt(byte[] cipher, BigInteger n, BigInteger d) {
BigInteger c = new BigInteger(1, cipher);
BigInteger m = c.modPow(d, n);
return m.toByteArray();
}
非常感谢!
您的消息不适合模数,这使得在执行模运算时丢失的信息无法找回。出于这个原因,RSA 通常与 AES 等对称加密相结合,其中 AES 密钥被加密。
我正在尝试在 Java 中编写 RSA 加密和解密函数,但遇到了一些麻烦:我认为是 BigInteger 和 byte[] 或反之亦然之间的转换引起的,有什么建议吗?
public byte[] encrypt(byte[] message, BigInteger n, BigInteger e) {
BigInteger m = new BigInteger(1, message);
BigInteger c = m.modPow(e, n);
return c.toByteArray();
}
public byte[] decrypt(byte[] cipher, BigInteger n, BigInteger d) {
BigInteger c = new BigInteger(1, cipher);
BigInteger m = c.modPow(d, n);
return m.toByteArray();
}
非常感谢!
您的消息不适合模数,这使得在执行模运算时丢失的信息无法找回。出于这个原因,RSA 通常与 AES 等对称加密相结合,其中 AES 密钥被加密。