Example usage for java.security Key hashCode

List of usage examples for java.security Key hashCode

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:edu.vt.middleware.crypt.util.CryptReaderWriterTest.java

/**
 * Gets a unique path to a private key.//from  ww w.j av a2s .  c  om
 *
 * @param  key  Private key.
 * @param  type  PEM or DER.
 * @param  password  Password on private key; may be null.
 *
 * @return  Path to key.
 */
private String getKeyPath(final Key key, final String type, final char[] password) {
    final StringBuffer sb = new StringBuffer();
    if (key instanceof PrivateKey) {
        sb.append("target/test-output/privkey_");
    } else if (key instanceof SecretKey) {
        sb.append("target/test-output/secretkey_");
    } else if (key instanceof PublicKey) {
        sb.append("target/test-output/pubkey_");
    } else {
        throw new IllegalArgumentException("Unrecognized key type.");
    }
    sb.append(key.getAlgorithm());
    sb.append("_");
    try {
        sb.append(fingerPrint(key));
    } catch (CryptException e) {
        sb.append(key.hashCode());
    }
    if (!(key instanceof PublicKey)) {
        if (password != null) {
            sb.append("_withpass");
        } else {
            sb.append("_nopass");
        }
    }
    sb.append('.');
    sb.append(type.toLowerCase());
    return sb.toString();
}