RSA in Java: BigInteger and byte[]



我正在尝试用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 密钥是加密的。

最新更新