Java中的RSA:BigInteger和byte[]

Java中的RSA:BigInteger和byte[],java,encryption,rsa,biginteger,Java,Encryption,Rsa,Biginteger,我正试图用Java编写RSA加密和解密函数,但遇到了一些问题:我认为是BigInteger和byte[]或viceversa之间的转换引起的,有什么建议吗 public byte[] encrypt(byte[] message, BigInteger n, BigInteger e) { BigInteger m = new BigInteger(1, message); BigInteger c = m.modPow(e, n); return c.toByteArr

我正试图用Java编写RSA加密和解密函数,但遇到了一些问题:我认为是BigInteger和byte[]或viceversa之间的转换引起的,有什么建议吗

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密钥被加密。

“我遇到了一些问题。”是的,您在指示出现了什么问题时遇到了问题。对不起,这似乎是真的。解密后的数组与消息数组不同,即加密和解密后的字节数组比消息数组小得多(约14000对274个条目…)。好吧,它对我有用。@gabse15模n,记得吗?你可以把这个值变回更大的值。混合加密。@MaartenBodewes哦。。。那么,对小于n的块进行加密/解密有意义吗?