Example usage for java.security Key equals

List of usage examples for java.security Key equals

Introduction

In this page you can find the example usage for java.security Key equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImplTest.java

/**
 * Test method for {@link net.sf.taverna.t2.security.credentialmanager.impl.CredentialManagerImpl#exportKeyPair(java.lang.String, java.io.File, java.lang.String)}.
 * @throws CMException /*from w w w .  ja va  2 s  .  c om*/
 * @throws KeyStoreException 
 * @throws NoSuchAlgorithmException 
 * @throws UnrecoverableKeyException 
 */
@Test
public void testExportKeyPair()
        throws CMException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException {
    String alias = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
    File fileToExportTo = new File(credentialManagerDirectory, "test-export-key.p12");
    credentialManager.exportKeyPair(alias, fileToExportTo, privateKeyAndPKCS12KeystorePassword);
    assertTrue(fileToExportTo.exists());
    // Load it back from the file we just saved
    KeyStore ks = credentialManager.loadPKCS12Keystore(fileToExportTo, privateKeyAndPKCS12KeystorePassword);
    Enumeration<String> aliases = ks.aliases();
    Key newPrivateKey = null;
    Certificate[] newPrivateKeyCerts = null;
    while (aliases.hasMoreElements()) {
        // The test-private-key-cert.p12 file contains only one private key
        // and corresponding certificate entry
        alias = aliases.nextElement();
        if (ks.isKeyEntry(alias)) { // is it a (private) key entry?
            newPrivateKey = ks.getKey(alias, privateKeyAndPKCS12KeystorePassword.toCharArray());
            newPrivateKeyCerts = ks.getCertificateChain(alias);
            break;
        }
    }
    assertNotNull(newPrivateKey);
    assertNotNull(newPrivateKeyCerts);
    //assertTrue(Arrays.equals(newPrivateKey.getEncoded(), privateKey.getEncoded()));
    assertTrue(newPrivateKey.equals(privateKey));
    assertTrue(Arrays.equals(newPrivateKeyCerts, privateKeyCertChain));
}

From source file:org.apache.taverna.security.credentialmanager.impl.CredentialManagerImplTest.java

/**
 * Test method for {@link org.apache.taverna.security.credentialmanager.impl.CredentialManagerImpl#exportKeyPair(java.lang.String, java.io.File, java.lang.String)}.
 * @throws CMException //from  ww  w . j a  va 2 s .co m
 * @throws KeyStoreException 
 * @throws NoSuchAlgorithmException 
 * @throws UnrecoverableKeyException 
 */
@Test
public void testExportKeyPair()
        throws CMException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException {
    String alias = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
    File fileToExportTo = new File(credentialManagerDirectory, "test-export-key.p12");
    credentialManager.exportKeyPair(alias, fileToExportTo.toPath(), privateKeyAndPKCS12KeystorePassword);
    assertTrue(fileToExportTo.exists());
    // Load it back from the file we just saved
    KeyStore ks = credentialManager.loadPKCS12Keystore(fileToExportTo.toPath(),
            privateKeyAndPKCS12KeystorePassword);
    Enumeration<String> aliases = ks.aliases();
    Key newPrivateKey = null;
    Certificate[] newPrivateKeyCerts = null;
    while (aliases.hasMoreElements()) {
        // The test-private-key-cert.p12 file contains only one private key
        // and corresponding certificate entry
        alias = aliases.nextElement();
        if (ks.isKeyEntry(alias)) { // is it a (private) key entry?
            newPrivateKey = ks.getKey(alias, privateKeyAndPKCS12KeystorePassword.toCharArray());
            newPrivateKeyCerts = ks.getCertificateChain(alias);
            break;
        }
    }
    assertNotNull(newPrivateKey);
    assertNotNull(newPrivateKeyCerts);
    //assertTrue(Arrays.equals(newPrivateKey.getEncoded(), privateKey.getEncoded()));
    assertTrue(newPrivateKey.equals(privateKey));
    assertTrue(Arrays.equals(newPrivateKeyCerts, privateKeyCertChain));
}