Example usage for java.security.interfaces ECPrivateKey getS

List of usage examples for java.security.interfaces ECPrivateKey getS

Introduction

In this page you can find the example usage for java.security.interfaces ECPrivateKey getS.

Prototype

BigInteger getS();

Source Link

Document

Returns the private value S.

Usage

From source file:org.cesecore.keys.util.KeyTools.java

/**
 * Test if a private key is extractable (could be stored).
 * //w  ww. ja v  a  2s .co  m
 * @param privK
 *            key to test.
 * @return true if the key is extractable.
 */
public static boolean isPrivateKeyExtractable(final PrivateKey privK) {
    if (privK instanceof RSAPrivateKey) {
        final RSAPrivateKey rsa = (RSAPrivateKey) privK;
        final BigInteger result = rsa.getPrivateExponent();
        return result != null && result.bitLength() > 0;
    }
    if (privK instanceof ECPrivateKey) {
        final ECPrivateKey ec = (ECPrivateKey) privK;
        final BigInteger result = ec.getS();
        return result != null && result.bitLength() > 0;
    }
    if (privK instanceof DHPrivateKey) {
        final DHPrivateKey dh = (DHPrivateKey) privK;
        final BigInteger result = dh.getX();
        return result != null && result.bitLength() > 0;
    }
    if (privK instanceof DSAPrivateKey) {
        final DSAPrivateKey dsa = (DSAPrivateKey) privK;
        final BigInteger result = dsa.getX();
        return result != null && result.bitLength() > 0;
    }
    return false;
}