Code example for X509EncodedKeySpec

0
    public static PublicKey publicKeyFrom(byte[] derBytes)
            throws InvalidKeySpecException 
    { 
        try { 
            KeyFactory keyFactory = KeyFactory.getInstance(RSA);
            EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(derBytes);
            PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
            return publicKey;
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(e);
        } 
    } 
 
    // Extracted from: 
    // http://oauth.googlecode.com/svn/code/branches/jmeter/jmeter/src/main/java/org/apache/jmeter/protocol/oauth/sampler/PrivateKeyReader.java 
    // See p.41 of http://www.emc.com/emc-plus/rsa-labs/pkcs/files/h11300-wp-pkcs-1v2-2-rsa-cryptography-standard.pdf 
    /**************************************************************************** 
     * Amazon Modifications: Copyright 2014 Amazon.com, Inc. or its affiliates.  
     * All Rights Reserved. 
     ***************************************************************************** 
Experience pair programming with AI  Get Codota for Java