Hi, i have to store a public key and a private one into a sqlite database. Actually i write the pubKey.getEncoded() into the database, and to recreate the 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 it gives me the following error
Exception in thread "main" java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: Detect premature EOF
at this point :
pubKey = (RSAPublicKey) rsaKeyFac.generatePublic(keySpec);
Anyone can help me?
Thank you in advance