Example usage for java.security.spec InvalidKeySpecException printStackTrace

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

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:se.leap.bitmaskclient.ConfigHelper.java

protected static RSAPrivateKey parseRsaKeyFromString(String RsaKeyString) {
    RSAPrivateKey key = null;/*from   w ww  .  j  a v a 2s  . c om*/
    try {
        KeyFactory kf = KeyFactory.getInstance("RSA", "BC");

        RsaKeyString = RsaKeyString.replaceFirst("-----BEGIN RSA PRIVATE KEY-----", "")
                .replaceFirst("-----END RSA PRIVATE KEY-----", "");
        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decode(RsaKeyString, Base64.DEFAULT));
        key = (RSAPrivateKey) kf.generatePrivate(keySpec);
    } catch (InvalidKeySpecException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    } catch (NoSuchProviderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }

    return key;
}