Java RSA加密-尝试加密消息时返回错误的值

Java RSA加密-尝试加密消息时返回错误的值,java,encryption,rsa,biginteger,Java,Encryption,Rsa,Biginteger,我为每个变量输入值以获取加密消息。所有这些都是硬编码的,用于测试目的 这将返回值?,该值应返回538 1729 1328 1328 2146。有什么是我放错的吗?这是我的代码唯一的问题 public static void main(String[] args){ int p = 61; int q = 37; int pq = p * q; int phiPQ = (p - 1) * (q - 1); int e = 7; int d = 154

我为每个变量输入值以获取加密消息。所有这些都是硬编码的,用于测试目的

这将返回值
,该值应返回
538 1729 1328 1328 2146
。有什么是我放错的吗?这是我的代码唯一的问题

public static void main(String[] args){
    int p = 61;
    int q = 37;
    int pq = p * q;
    int phiPQ = (p - 1) * (q - 1);
    int e = 7;
    int d = 1543;
    String message = encryptMsg("hello", pq, e);
    System.out.println(message);
}

public static String encryptMsg(String msg, int pq, int e){
    BigInteger bE = new BigInteger(Integer.toString(e));
    BigInteger bPQ = new BigInteger(Integer.toString(pq));
    String encryptedMsg = "";
    for(int i = 0; i < msg.length(); i++){
        BigInteger m = new BigInteger(Integer.toString(msg.charAt(i)));
        BigInteger bC = m.modPow(bE, bPQ);
        encryptedMsg += " " + (char)bC.intValue();
    }
    return encryptedMsg;
}
publicstaticvoidmain(字符串[]args){
int p=61;
int q=37;
int pq=p*q;
int-phiPQ=(p-1)*(q-1);
int e=7;
int d=1543;
字符串消息=encryptMsg(“你好”,pq,e);
System.out.println(消息);
}
公共静态字符串encryptMsg(字符串消息,int pq,int e){
BigInteger bE=新的BigInteger(Integer.toString(e));
BigInteger bPQ=新的BigInteger(Integer.toString(pq));
字符串encryptedMsg=“”;
对于(int i=0;i
我想你可能想要

encryptedMsg +=" " + bC.toString();

目前,您正在将整数强制转换为一个字符,因此,我想返回unicode,而您似乎期望的是整数作为字符串。

Btw:结果的第一个值是1039,而不是538。