Java 8 X509EncodedKeySpec - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 X509EncodedKeySpec class.

This code example shows how to use the following methods:
        return cipher;
    } 
 
    public static PublicKey getPubkey(EncryptionRequest request) throws GeneralSecurityException
    { 
        return KeyFactory.getInstance( "RSA" ).generatePublic( new X509EncodedKeySpec( request.getPublicKey() ) );
    } 
 
    public static byte[] encrypt(Key key, byte[] b) throws GeneralSecurityException
    { 
        Cipher hasher = Cipher.getInstance( "RSA" );
        hasher.init( Cipher.ENCRYPT_MODE, key );
        return hasher.doFinal( b );
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
     */ 
    public static PublicKey generatePublicKey(String encodedPublicKey) {
        try { 
            byte[] decodedKey = Base64.decode(encodedPublicKey);
            KeyFactory keyFactory = KeyFactory.getInstance(KEY_FACTORY_ALGORITHM);
            return keyFactory.generatePublic(new X509EncodedKeySpec(decodedKey));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (InvalidKeySpecException e) {
            Log.e(TAG, "Invalid key specification.");
            throw new IllegalArgumentException(e);
        } catch (Base64DecoderException e) {
            Log.e(TAG, "Base64 decoding failed.");
            throw new IllegalArgumentException(e);
        } 
    } 
 
    /** 
     * Verifies that the signature from the server matches the computed 
     * signature on the data.  Returns true if the data is correctly signed. 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		} 
	} 
 
	public void setPublicKey(byte[] encoded) {
		if (encoded == null) return;
		final X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encoded);
		if (type != null) {
			publicKey = decodePublicKeyAs(pubKeySpec, type);
		} else { 
			publicKey = decodePublicKeyAs(pubKeySpec, KEY_TYPE_RSA);
			if (publicKey != null) {
				type = KEY_TYPE_RSA;
			} else { 
				publicKey = decodePublicKeyAs(pubKeySpec, KEY_TYPE_DSA);
				if (publicKey != null) {
					type = KEY_TYPE_DSA;
				} 
			} 
		} 
	} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        writeUTF(new String(Base64.encodeBase64(key.getEncoded())));
    } 
 
    public X509EncodedKeySpec readKey() throws IOException {
        byte[] otherHalf = Base64.decodeBase64(readUTF());
        return new X509EncodedKeySpec(otherHalf);
    } 
 
    /** 
     * Performs a Diffie-Hellman key exchange and produce a common secret between two ends of the connection. 
     * 
     * <p> 
     * DH is also useful as a coin-toss algorithm. Two parties get the same random number without trusting 
     * each other. 
     */ 
    public KeyAgreement diffieHellman(boolean side) throws IOException, GeneralSecurityException {
        KeyPair keyPair;
        PublicKey otherHalf;
 
        if (side) {

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
This code example shows how to use the following methods:
    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. 
     ***************************************************************************** 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        return cipher;
    } 
 
    public static PublicKey getPubkey(EncryptionRequest request) throws GeneralSecurityException
    { 
        return KeyFactory.getInstance( "RSA" ).generatePublic( new X509EncodedKeySpec( request.getPublicKey() ) );
    } 
 
    public static byte[] encrypt(Key key, byte[] b) throws GeneralSecurityExceptionCipher hasher = Cipher.getInstance( "RSA" );
        hasher.init( Cipher.ENCRYPT_MODE, key );
        return hasher.doFinal( b );
    } 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
      return null; 
    } 
     
    try { 
      KeyFactory fac = KeyFactory.getInstance("RSA");
      EncodedKeySpec spec = new X509EncodedKeySpec(publicKey);
      return fac.generatePublic(spec);
    } 
    catch (NoSuchAlgorithmException e) {
      throw new IllegalStateException(e);
    } 
    catch (InvalidKeySpecException e) {
      throw new IllegalStateException(e);
    } 
  } 
 
  /** 
   * Creates a private key from the PKCS#8-encoded value of the given bytes. 
   * 
   * @param privateKey The PKCS#8-encoded private key bytes. 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		} 
	} 
 
	public void setPublicKey(byte[] encoded) {
		if (encoded == null) return;
		final X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encoded);
		if (type != null) {
			publicKey = decodePublicKeyAs(pubKeySpec, type);
		} else { 
			publicKey = decodePublicKeyAs(pubKeySpec, KEY_TYPE_RSA);
			if (publicKey != null) {
				type = KEY_TYPE_RSA;
			} else { 
				publicKey = decodePublicKeyAs(pubKeySpec, KEY_TYPE_DSA);
				if (publicKey != null) {
					type = KEY_TYPE_DSA;
				} 
			} 
		} 
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
     */ 
    public static PublicKey generatePublicKey(String encodedPublicKey) {
        try { 
            byte[] decodedKey = Base64.decode(encodedPublicKey);
            KeyFactory keyFactory = KeyFactory.getInstance(KEY_FACTORY_ALGORITHM);
            return keyFactory.generatePublic(new X509EncodedKeySpec(decodedKey));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (InvalidKeySpecException e) {
            Log.e(TAG, "Invalid key specification.");
            throw new IllegalArgumentException(e);
        } catch (Base64DecoderException e) {
            Log.e(TAG, "Base64 decoding failed.");
            throw new IllegalArgumentException(e);
        } 
    } 
 
    /** 
     * Verifies that the signature from the server matches the computed 
     * signature on the data.  Returns true if the data is correctly signed. 
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 X509EncodedKeySpec Questions & Answers:

See Code Examples for Java 8 X509EncodedKeySpec Methods: