简体   繁体   中英

Error when getting key from KeyStore (java)

I'm facing a very weird error. This error started to happen today, it was working on Friday, and nothing changed, at least nothing I know.

I have a simple KeyStore where I store a key to encrypt some data. Just for testing a created a separate application to handle this. This is the code:

public static void main(String[] args) {

    Properties prop = new Properties();
    try {

       prop.load(new FileInputStream("./security/security.properties"));

       String ksFile = prop.getProperty("KSFile");
       String ksPassword = prop.getProperty("KSPassword");
       String keyAlias = prop.getProperty("KeyAlias");
       String keyPassword = prop.getProperty("KeyPassword");
       prop.getProperty("CardDataEncryptionKey");

       KeyStore ks;
       ks = KeyStore.getInstance("JCEKS");

       FileInputStream fis = null;
       fis = new FileInputStream(ksFile);

       ks.load(fis, ksPassword.toCharArray());


       // For symmetric
       char[] keycharArray = keyPassword.toCharArray();
       ProtectionParameter proParam = new KeyStore.PasswordProtection( keycharArray );

       KeyStore.Entry entry = ks.getEntry( keyAlias, proParam );
       SecretKeyEntry aeskey = (KeyStore.SecretKeyEntry) entry;         

       aeskey.getSecretKey();


       fis.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

Code is very basic and just open the keystore configured in security.properties. The problem is now I'm getting an error in the following line:

       KeyStore.Entry entry = ks.getEntry( keyAlias, proParam );

I repeat this wasn't happening, just started suddenly. File is ok, paths are ok, the file is opened, but when I try to get the KeyEntry, I'm getting a NumberFormatException, really don't have a clue if what's going on. This is the error stack trace:

Test at localhost:62013 
    Thread [main] (Suspended (exception NumberFormatException)) 
        owns: InetAddress$Cache  (id=58)    
        owns: Object  (id=59)   
        Integer.parseInt(String, int) line: not available   
        Integer.<init>(String) line: not available  
        InetAddressCachePolicy.<clinit>() line: not available   
        InetAddress$Cache.getPolicy() line: not available   
        InetAddress$Cache.put(String, InetAddress[]) line: not available    
        InetAddress.cacheInitIfNeeded() line: not available 
        InetAddress.cacheAddresses(String, InetAddress[], boolean) line: not available  
        InetAddress.getAddressesFromNameService(String, InetAddress) line: not available    
        InetAddress.getLocalHost() line: not available  
        JarVerifier.getSystemEntropy() line: 783    
        JarVerifier.testSignatures(X509Certificate, CertificateFactory) line: 706   
        JarVerifier.access$400(X509Certificate, CertificateFactory) line: 34    
        JarVerifier$1.run() line: 183   
        JarVerifier$1.run() line: 149   
        AccessController.doPrivileged(PrivilegedExceptionAction<T>) line: not available [native method] 
        JarVerifier.<clinit>() line: 148    
        JceSecurity.loadPolicies(File, CryptoPermissions, CryptoPermissions) line: 316  
        JceSecurity.setupJurisdictionPolicies() line: 261   
        JceSecurity.access$000() line: 48   
        JceSecurity$1.run() line: 78    
        AccessController.doPrivileged(PrivilegedExceptionAction<T>) line: not available [native method] 
        JceSecurity.<clinit>() line: 76 
        JceSecurityManager.<clinit>() line: 65  
        CipherForKeyProtector(Cipher).<init>(CipherSpi, Provider, String) line: 252 
        CipherForKeyProtector.<init>(CipherSpi, Provider, String) line: 377 
        KeyProtector.unseal(SealedObject) line: 347 
        JceKeyStore.engineGetKey(String, char[]) line: 133  
        JceKeyStore(KeyStoreSpi).engineGetEntry(String, KeyStore$ProtectionParameter) line: not available   
        KeyStore.getEntry(String, KeyStore$ProtectionParameter) line: not available 
        Test.main(String[]) line: 39    

Please guys, give me a light of hope! Thank you!

Finally it was an Eclipse problem, also don't know really why it happened. I started to get this error after I changed my domain password, even though I restarted Windows twice.

Who knows! Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM