Example usage for java.security InvalidKeyException initCause

List of usage examples for java.security InvalidKeyException initCause

Introduction

In this page you can find the example usage for java.security InvalidKeyException initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:org.ejbca.core.protocol.cmp.CrmfRequestMessage.java

private PublicKey getPublicKey(final SubjectPublicKeyInfo subjectPKInfo, final String provider)
        throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException {
    try {//from  w  w w.  j  a  v a2  s. c o  m
        final X509EncodedKeySpec xspec = new X509EncodedKeySpec(new DERBitString(subjectPKInfo).getBytes());
        final AlgorithmIdentifier keyAlg = subjectPKInfo.getAlgorithm();
        return KeyFactory.getInstance(keyAlg.getAlgorithm().getId(), provider).generatePublic(xspec);
    } catch (java.security.spec.InvalidKeySpecException e) {
        final InvalidKeyException newe = new InvalidKeyException("Error decoding public key.");
        newe.initCause(e);
        throw newe;
    } catch (IOException e) {
        final InvalidKeyException newe = new InvalidKeyException("Error decoding public key.");
        newe.initCause(e);
        throw newe;
    }
}