Java 8 PrivateKey - 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 PrivateKey class.

This code example shows how to use the following methods:getAlgorithm, getFormat
        KeyFactory keyFactory
        = KeyFactory.getInstance("RSA");
        PrivateKey privateKey
        = keyFactory.generatePrivate(privateKeySpec);
         
        System.out.println("Loaded " + privateKey.getAlgorithm()
                   + " " + privateKey.getFormat()
                   + " private key."); 
        return privateKey;
    } finally { 
        // Dynamically deinstall the RSA provider  
        Security.removeProvider(provider.getName());
    } 
    } 
     
    /* ------------------------------------------------------------ */ 
    /** 
     * Show a usage message. 
     */ 
    static private void usage() 
6
CodeRank
This code example shows how to use the following methods:getEncoded
This code example shows how to use the following methods:equals
        throws IOException 
    { 
        StringWriter sw = new StringWriter();
        PEMWriter pw = new PEMWriter(sw);
 
        pw.writeObject(akp);
        pw.close();
 
        String data = sw.toString();
 
        PEMParser pr = new PEMParser(new StringReader(data));
 
        Object o = pr.readObject();
 
        if (o == null || !(o instanceof PEMKeyPair))
        { 
            fail("Didn't find OpenSSL key"); 
        } 
 
        KeyPair kp = new JcaPEMKeyConverter().setProvider("BC").getKeyPair((PEMKeyPair)o);

6
CodeRank
This code example shows how to use the following methods:hashCode, getEncoded
This code example shows how to use the following methods:getEncoded, getFormat
			return null; 
		} 
	} 
 
	protected byte[] getEncoded(PrivateKey key) {
		String format = key.getFormat();
		if (format != null
				&& (format.equalsIgnoreCase("PKCS#8") || format
						.equalsIgnoreCase("PKCS8"))) {
			try { 
				ASN1Primitive keyInfo = BouncyCastleUtil.toASN1Primitive(key
						.getEncoded());
				PrivateKeyInfo pkey = new PrivateKeyInfo((ASN1Sequence) keyInfo);
				ASN1Primitive derKey = pkey.getPrivateKey();
				return BouncyCastleUtil.toByteArray(derKey);
			} catch (IOException e) {
				// that should never happen 
				logger.warn("This shouldn't have happened.", e);
				return new byte[] {}; 
			} 
6
CodeRank
This code example shows how to use the following methods:getAlgorithm, getFormat
    } 
 
    @Test
    public void testLoadPrivateKey() throws Exception {
        PrivateKey key = keyLoader.loadPrivateKey();
        assertEquals("RSA", key.getAlgorithm());
        assertEquals("PKCS#8", key.getFormat());
    } 
 
    @Override 
    public boolean isUseRouteBuilder() { 
        return false; 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getEncoded
public class JcaPKCS8EncryptedPrivateKeyInfoBuilder 
    extends PKCS8EncryptedPrivateKeyInfoBuilder 
{ 
    public JcaPKCS8EncryptedPrivateKeyInfoBuilder(PrivateKey privateKey)
    { 
         super(PrivateKeyInfo.getInstance(privateKey.getEncoded()));
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getAlgorithm, getFormat
    } 
 
    @Test
    public void testLoadPrivateKey() throws Exception {
        PrivateKey key = keyLoader.loadPrivateKey();
        assertEquals("RSA", key.getAlgorithm());
        assertEquals("PKCS#8", key.getFormat());
    } 
 
    @Override 
    public boolean isUseRouteBuilder() { 
        return false; 
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:getEncoded
    extends PKCS8Generator 
{ 
    public JcaPKCS8Generator(PrivateKey key, OutputEncryptor encryptor)
         throws PemGenerationException 
    { 
         super(PrivateKeyInfo.getInstance(key.getEncoded()), encryptor);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getEncoded
        this(privateKey, X500Name.getInstance(name.getEncoded()));
    } 
 
    public JcaPKIArchiveControlBuilder(PrivateKey privateKey, GeneralName generalName)
    { 
        super(PrivateKeyInfo.getInstance(privateKey.getEncoded()), generalName);
    } 
} 
5
CodeRank

Related Java 8 PrivateKey Questions & Answers:

See Code Examples for Java 8 PrivateKey Methods: