Example usage for org.bouncycastle.bcpg PublicKeyAlgorithmTags ECDSA

List of usage examples for org.bouncycastle.bcpg PublicKeyAlgorithmTags ECDSA

Introduction

In this page you can find the example usage for org.bouncycastle.bcpg PublicKeyAlgorithmTags ECDSA.

Prototype

int ECDSA

To view the source code for org.bouncycastle.bcpg PublicKeyAlgorithmTags ECDSA.

Click Source Link

Usage

From source file:com.google.e2e.bcdriver.KeyChecker.java

License:Apache License

private static final boolean canSign(int algorithm) {
    return (algorithm == PublicKeyAlgorithmTags.RSA_GENERAL) || (algorithm == PublicKeyAlgorithmTags.RSA_SIGN)
            || (algorithm == PublicKeyAlgorithmTags.DSA) || (algorithm == PublicKeyAlgorithmTags.ECDSA);
}

From source file:org.sufficientlysecure.keychain.pgp.PgpSecurityConstants.java

License:Open Source License

public static boolean isSecureKey(CanonicalizedPublicKey key) {
    switch (key.getAlgorithm()) {
    case PublicKeyAlgorithmTags.RSA_GENERAL: {
        return (key.getBitStrength() >= 2048);
    }/*  w  w  w  .ja v a  2s.co m*/
    // RSA_ENCRYPT, RSA_SIGN: deprecated in RFC 4880, use RSA_GENERAL with key flags
    case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT: {
        return (key.getBitStrength() >= 2048);
    }
    case PublicKeyAlgorithmTags.DSA: {
        return (key.getBitStrength() >= 2048);
    }
    case PublicKeyAlgorithmTags.ECDH:
    case PublicKeyAlgorithmTags.ECDSA: {
        return PgpSecurityConstants.sCurveWhitelist.contains(key.getCurveOid());
    }
    // ELGAMAL_GENERAL: deprecated in RFC 4880, use ELGAMAL_ENCRYPT
    // DIFFIE_HELLMAN: unsure
    default:
        return false;
    }
}

From source file:org.sufficientlysecure.keychain.securitytoken.KeyFormat.java

License:Open Source License

public static KeyFormat fromBytes(byte[] bytes) {
    switch (bytes[0]) {
    case PublicKeyAlgorithmTags.RSA_GENERAL:
        if (bytes.length < 6) {
            throw new IllegalArgumentException("Bad length for RSA attributes");
        }/*from w ww  .j  ava 2s  .  co  m*/
        return new RSAKeyFormat(bytes[1] << 8 | bytes[2], bytes[3] << 8 | bytes[4],
                RSAKeyFormat.RSAAlgorithmFormat.from(bytes[5]));

    case PublicKeyAlgorithmTags.ECDH:
    case PublicKeyAlgorithmTags.ECDSA:
        if (bytes.length < 2) {
            throw new IllegalArgumentException("Bad length for RSA attributes");
        }
        int len = bytes.length - 1;
        if (bytes[bytes.length - 1] == (byte) 0xff) {
            len -= 1;
        }
        final byte[] boid = new byte[2 + len];
        boid[0] = (byte) 0x06;
        boid[1] = (byte) len;
        System.arraycopy(bytes, 1, boid, 2, len);
        final ASN1ObjectIdentifier oid = ASN1ObjectIdentifier.getInstance(boid);
        return new ECKeyFormat(oid, ECKeyFormat.ECAlgorithmFormat.from(bytes[0], bytes[bytes.length - 1]));

    default:
        throw new IllegalArgumentException("Unsupported Algorithm id " + bytes[0]);
    }
}

From source file:org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.java

License:Open Source License

/**
 * Based on <a href="http://tools.ietf.org/html/rfc2440#section-9.1">OpenPGP Message Format</a>
 *//*from w w w . j  a va 2  s  . c  o m*/
public static String getAlgorithmInfo(Context context, int algorithm, Integer keySize, String oid) {
    String algorithmStr;

    switch (algorithm) {
    case PublicKeyAlgorithmTags.RSA_GENERAL:
    case PublicKeyAlgorithmTags.RSA_ENCRYPT:
    case PublicKeyAlgorithmTags.RSA_SIGN: {
        algorithmStr = "RSA";
        break;
    }
    case PublicKeyAlgorithmTags.DSA: {
        algorithmStr = "DSA";
        break;
    }

    case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT:
    case PublicKeyAlgorithmTags.ELGAMAL_GENERAL: {
        algorithmStr = "ElGamal";
        break;
    }

    case PublicKeyAlgorithmTags.ECDSA: {
        if (oid == null) {
            return "ECDSA";
        }
        String oidName = KeyFormattingUtils.getCurveInfo(context, oid);
        return "ECDSA (" + oidName + ")";
    }
    case PublicKeyAlgorithmTags.ECDH: {
        if (oid == null) {
            return "ECDH";
        }
        String oidName = KeyFormattingUtils.getCurveInfo(context, oid);
        return "ECDH (" + oidName + ")";
    }

    default: {
        if (context != null) {
            algorithmStr = context.getResources().getString(R.string.unknown_algorithm);
        } else {
            algorithmStr = "unknown";
        }
        break;
    }
    }
    if (keySize != null && keySize > 0)
        return algorithmStr + ", " + keySize + " bit";
    else
        return algorithmStr;
}