KeyFactory generatePublic - top ranked examples from Open Source projects

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

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
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
This code example shows how to use the following methods:generatePrivate, generatePublic
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
This code example shows how to use the following methods:
	int exponentLength = readInt(keyByteArray, modulusLength + 4);
	byte[] exponentByteArray = new byte[exponentLength];
	System.arraycopy(keyByteArray, modulusLength + 8, exponentByteArray, 0, exponentLength);
	BigInteger publicExponent = new BigInteger(1, exponentByteArray);
 
	return KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, publicExponent));
    } 
 
    /** 
     * Encrypts given string with Google Public Key. 
     *  
     */ 
    public static String encryptString(String str2Encrypt) throws Exception {
 
	byte[] keyByteArray = Base64.decode(GOOGLE_PUBLIC_KEY, Base64.DEFAULT);
 
	byte[] header = new byte[5];
	byte[] digest = MessageDigest.getInstance("SHA-1").digest(keyByteArray);
	header[0] = 0;
	System.arraycopy(digest, 0, header, 1, 4);
6
CodeRank
This code example shows how to use the following methods:
	public static CryptorRSA fromString(String publicKey, String privateKey) throws Exception
	{ 
		return  
			new CryptorRSAJCE( 
				publicKey != null ?
					KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(
						Base64.decode(publicKey))
					) : 
					null, 
				privateKey != null ?
					KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(
						Base64.decode(privateKey))
					) : 
					null 
			);					 
	} 
	 
} 
6
CodeRank
This code example shows how to use the following methods:
  public void setChallengeToken(byte[] challangeToken) {
    challengeToken = challangeToken;
  } 
 
  private static PublicKey getPublicKey(byte[] keyBytes) throws GeneralSecurityException {
    return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(keyBytes));
  } 
 
  private static SecretKey generateSharedKey() throws NoSuchAlgorithmException {
    KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
    keyGenerator.init(128);
    return keyGenerator.generateKey();
  } 
 
  private static byte[] loginHash(String name, PublicKey publicKey, SecretKey sharedKey) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    return getHash("SHA-1", new byte[][] { name.getBytes("ISO_8859_1"), sharedKey.getEncoded(), publicKey.getEncoded() });
  } 
 
  private static byte[] getHash(String algrithm, byte[][] data) throws NoSuchAlgorithmException {
    MessageDigest digest = MessageDigest.getInstance(algrithm);
6
CodeRank
This code example shows how to use the following methods:generatePrivate, generatePublic
            fail(e.getMessage());
        } 
 
        PrivateKey privateKey = null;
        try { 
            privateKey = factory.generatePrivate(privateKeySpec);
        } catch (InvalidKeySpecException e) {
            fail(e.getMessage());
        } 
 
        PublicKeySpec publicKeySpec = null;
        try { 
            publicKeySpec = factory.getKeySpec(DefaultKeys.getPublicKey(algorithmName),
                    publicKeySpecClass);
        } catch (InvalidKeySpecException e) {
            fail(e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            fail(e.getMessage());
        } 
 

6
CodeRank
This code example shows how to use the following methods:
    public PublicKey getPublicKey(Provider provider)
        throws NoSuchAlgorithmException, InvalidKeySpecException, IOException
    { 
        SubjectPublicKeyInfo subjectPKInfo = pkac.getSubjectPublicKeyInfo();
 
        X509EncodedKeySpec xspec = new X509EncodedKeySpec(new DERBitString(subjectPKInfo).getBytes());
 
        return KeyFactory.getInstance(subjectPKInfo.getAlgorithmId().getAlgorithm().getId(), provider)
            .generatePublic(xspec);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:generatePrivate, generatePublic, getKeySpec
        ) 
    }) 
    public void testKeyFactory() { 
        PrivateKeySpec privateKeySpec = null;
        try { 
            privateKeySpec = factory.getKeySpec(DefaultKeys.getPrivateKey(algorithmName),
                    privateKeySpecClass);
        } catch (InvalidKeySpecException e) {
            fail(e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            fail(e.getMessage());
        } 
 
        PrivateKey privateKey = null;
        try { 
            privateKey = factory.generatePrivate(privateKeySpec);
        } catch (InvalidKeySpecException e) {
            fail(e.getMessage());
        } 
 

5
CodeRank

Related KeyFactory generatePublic Questions & Answers:

generatePublic Method Overview
Generates a public key object from the provided key specification (key material).
See Code Examples for other Java 8 KeyFactory Methods: