File f = new File(filename); FileInputStream fis = new FileInputStream(f); DataInputStream dis = new DataInputStream(fis); byte[] keyBytes = new byte[(int) f.length()]; dis.readFully(keyBytes); dis.close(); RSAPrivateKeySpec spec = new RSAPrivateKeySpec(new BigInteger(keyBytes),new BigInteger(keyBytes)); KeyFactory kf = KeyFactory.getInstance("RSA"); kf.generatePrivate(spec); 

The file opens, but the question arose how to find out the modulus and the private exponent with a sequence of keyBytes bytes. RSAPrivateKeySpec should receive modulus and private exponent as input parameters, I don’t have these values ​​and I inserted new BigInteger (keyByte) everywhere, but this is not correct and, accordingly, can not be decrypted, encrypted with such a key.

  • The format of this file is not documented? - renegator
  • I did not find an answer for myself, can you tell me? - G1yyK
  • Well, for starters, it would be nice to know where it came from. - renegator
  • the key was generated by gpg --gen-key - answered all the wizard's questions and received an entry in the repository. after that I export the gpg key - export-secret-key -a -o mysecret.key - G1yyK
  • one
    I think GPG should have a key import function, similar to CryptoAPI, which I more or less understand. It is worth rummaging for this - renegator

0