X509EncodedKeySpec getEncoded - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for X509EncodedKeySpec getEncoded method.

This code example shows how to use the following methods:getEncoded
        } else if (keySpec instanceof X509EncodedKeySpec) {
            X509EncodedKeySpec x509KeySpec = (X509EncodedKeySpec) keySpec;
 
            try { 
                final OpenSSLKey key = new OpenSSLKey(
                        NativeCrypto.d2i_PUBKEY(x509KeySpec.getEncoded()));
                return new OpenSSLRSAPublicKey(key);
            } catch (Exception e) {
                throw new InvalidKeySpecException(e);
            } 
        } 
        throw new InvalidKeySpecException("Must use RSAPublicKeySpec or X509EncodedKeySpec; was "
                + keySpec.getClass().getName());
    } 
 
    @Override 
    protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException {
        if (keySpec instanceof RSAPrivateCrtKeySpec) {
            RSAPrivateCrtKeySpec rsaKeySpec = (RSAPrivateCrtKeySpec) keySpec;
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getEncoded
     * Assertion: returns encoded key 
     */ 
    public final void testGetEncoded() { 
        byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4};
         
        X509EncodedKeySpec eks = new X509EncodedKeySpec(encodedKey);
         
        byte[] ek = eks.getEncoded();
         
        assertTrue(Arrays.equals(encodedKey, ek));
    } 
 
    /** 
     * Test for <code>getFormat()</code> method 
     * Assertion: returns format name (always "X.509") 
     */ 
    public final void testGetFormat() { 
        byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4};
         
        X509EncodedKeySpec meks = new X509EncodedKeySpec(encodedKey);
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getEncoded
     * Assertion: returns encoded key 
     */ 
    public final void testGetEncoded() { 
        byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4};
 
        X509EncodedKeySpec eks = new X509EncodedKeySpec(encodedKey);
 
        byte[] ek = eks.getEncoded();
 
        assertTrue(Arrays.equals(encodedKey, ek));
    } 
 
    /** 
     * Test for <code>getFormat()</code> method 
     * Assertion: returns format name (always "X.509") 
     */ 
    public final void testGetFormat() { 
        byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4};
 
        X509EncodedKeySpec meks = new X509EncodedKeySpec(encodedKey);
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getEncoded
		KeyPair keyPair = kpg.generateKeyPair();
		PrivateKey privateKey = keyPair.getPrivate();
		PublicKey publicKey = keyPair.getPublic();
		 
		// Store Public Key. 
		X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(publicKey.getEncoded());
		FileOutputStream fos = new FileOutputStream(dirPath + "/public.key");
		fos.write(x509EncodedKeySpec.getEncoded());
		fos.close();
		 
		// Store Private Key. 
		PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(privateKey.getEncoded());
		fos = new FileOutputStream(dirPath + "/private.key");
		fos.write(pkcs8EncodedKeySpec.getEncoded());
		fos.close();
	} 
 
	/** 
	 * This function is responsible for retrieving a public key from the specified public key file path 
	 * @param keyFilePath 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getEncoded
This code example shows how to use the following methods:getEncoded
This code example shows how to use the following methods:getEncoded
This code example shows how to use the following methods:getEncoded
    public static void saveKeyPair(KeyPair keyPair, OutputStream privateKeyOutput, OutputStream publicKeyOutput) throws IOException {
        PrivateKey privateKey = keyPair.getPrivate();
        PublicKey publicKey = keyPair.getPublic();
 
        // Store Public Key. 
        X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(
                publicKey.getEncoded());
        publicKeyOutput.write(x509EncodedKeySpec.getEncoded());
 
        // Store Private Key. 
        PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(
                privateKey.getEncoded());
        privateKeyOutput.write(pkcs8EncodedKeySpec.getEncoded());
    } 
 
    /** 
     * Create all required directories 
     * 
     * @param privateKeyFile the private key file 
     * @return the file 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getEncoded
This code example shows how to use the following methods:getEncoded
 
public class DSAKeyUtil { 
    private static final Logger log = LoggerFactory.getLogger(DSAKeyUtil.class); 
 
    public static String getHexStringFromPublicKey(PublicKey publicKey) {
        final X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(publicKey.getEncoded());
        return Utils.HEX.encode(x509EncodedKeySpec.getEncoded());
    } 
 
    public static KeyPair generateKeyPair() {
        try { 
            final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
            keyGen.initialize(1024);
            return keyGen.genKeyPair();
        } catch (NoSuchAlgorithmException e) {
            log.error(e.toString());
        } 
        return null; 
    } 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
getEncoded Method Overview
Returns the key bytes, encoded according to the X.509 standard.
See Code Examples for other Java 8 X509EncodedKeySpec Methods: