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 );
    } 
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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. 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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;
				} 
			} 
		} 
	} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods:

Related Java 8 X509EncodedKeySpec Questions & Answers:

See Code Examples for Java 8 X509EncodedKeySpec Methods: