I've written such code which should take 3 arguments, one is file with public key, second file to encrypt and third is file to save encrypted text. However, it does not work as it should, I added println just to see where it fails:
public class cipher {
public static void main (String[] args) throws GeneralSecurityException{
try {
FileInputStream keyfis = new FileInputStream(args[0]);
byte[] encKey = new byte[keyfis.available()];
System.out.println(encKey);
keyfis.read(encKey);
System.out.println(encKey);
System.out.println("1");
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encKey);
System.out.println(keySpec);
KeyFactory kf = KeyFactory.getInstance("RSA");
System.out.println("2");
PublicKey pubKey = kf.generatePublic(keySpec);
System.out.println("3r");
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE,pubKey);
System.out.println("4");
}
catch(Exception e)
{}
}
}
After invokation of program I have such output :
[B@938b4a
[B@938b4a
1
java.security.spec.X509EncodedKeySpec@182d86
2
Thanks for help!