I need to save public key and private to sqlite database. Actually, I am writing pubKey.getEncoded () to the database, and to recreate pubkey I use the following code:
ResultSet result = stat.executeQuery("select publickey from cert where id='1'");
KeyFactory rsaKeyFac = KeyFactory.getInstance("RSA");
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(result.getBytes(1));
RSAPublicKey pubKey;
pubKey = (RSAPublicKey) rsaKeyFac.generatePublic(keySpec);
but this gives me the following error:
Exception in thread "main" java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: detection of premature EOF
in this moment:
pubKey = (RSAPublicKey) rsaKeyFac.generatePublic (keySpec);
Can anybody help me?
Thank you in advance
source
share