-2
 public void writed()
    {
        try{
            FileOutputStream fos = new FileOutputStream("c:\\key01.txt"); 
            fos.write(d.toByteArray());
            System.out.println("Done");

        }catch(Exception e)
        {
            System.out.println("\nError in writed: " + e.getMessage());}
    }

privateKey = (RSAPrivateCrtKey)keypair.getPrivate();
p = privateKey.getPrimeP();
q = privateKey.getPrimeQ();
phiN = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
e = privateKey.getPublicExponent();
d = e.modInverse(phiN);

Any idea how to read the d from key01.txt? or better way to read and write the data from txt file?

4

2 回答 2

1

尝试这个:

FileInputStream inputStream = new FileInputStream("foo.txt");
try {
    String everything = IOUtils.toString(inputStream);
} finally {
        inputStream.close();
}

或者看看这个问题: Reading a plain text file in Java

于 2013-08-26T14:56:07.767 回答
0

首先是一个小题外话:给带有二进制内容的文件一个.txt扩展名是令人困惑的。

读回值:将文件内容读入字节数组,然后调用BigInteger(byte[] val)构造函数。

于 2013-08-26T14:58:30.523 回答