Example usage for java.security.spec InvalidKeySpecException getCause

List of usage examples for java.security.spec InvalidKeySpecException getCause

Introduction

In this page you can find the example usage for java.security.spec InvalidKeySpecException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.xinferin.licensing.LicenceActivator.java

private void initialiseKeys() throws Exception {
    try {// w ww  . j a v a  2 s.c  om

        byte[] publicKeyBytes = Base64.decodeBase64(spublicKey);

        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKeyBytes);
        publicKey = keyFactory.generatePublic(publicKeySpec);

    } catch (InvalidKeySpecException e) {
        throw new Exception("Invalid Key Specs not valid Key files." + e.getCause());
    } catch (NoSuchAlgorithmException e) {
        throw new Exception("There is no such algorithm. Please check the JDK ver." + e.getCause());
    }
}

From source file:com.xinferin.licensing.LicenceGenerator.java

/**
 * Main method to initialise the private key from the database
 * @throws Exception/* w  w w.ja v a2s.  co m*/
 */
private void initialisePrivateKey() throws Exception {

    if (encodedPrivateKey == null)
        throw new Exception("An encoded Base64 private key has not been specified.");

    try {
        //Read key files back and decode them from BASE64
        byte[] privateKeyBytes = Base64.decodeBase64(encodedPrivateKey);

        // Convert back to public and private key objects
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateKeyBytes);
        privateKey = keyFactory.generatePrivate(privateKeySpec);

    } catch (InvalidKeySpecException e) {
        throw new Exception("Invalid key specifications. Not a valid key entry." + e.getCause());
    } catch (NoSuchAlgorithmException e) {
        throw new Exception("There is no such algorithm. Please check the JDK ver." + e.getCause());
    }
}