Example usage for org.bouncycastle.asn1.nist NISTObjectIdentifiers id_sha512

List of usage examples for org.bouncycastle.asn1.nist NISTObjectIdentifiers id_sha512

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.nist NISTObjectIdentifiers id_sha512.

Prototype

ASN1ObjectIdentifier id_sha512

To view the source code for org.bouncycastle.asn1.nist NISTObjectIdentifiers id_sha512.

Click Source Link

Document

2.16.840.1.101.3.4.2.3

Usage

From source file:org.xipki.pki.ocsp.client.api.RequestOptions.java

License:Open Source License

public static RSASSAPSSparams createPSSRSAParams(final ASN1ObjectIdentifier digestAlgOid) {
    int saltSize;
    if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOid)) {
        saltSize = 20;//  w  w  w. j a  v a 2  s . c  o m
    } else if (NISTObjectIdentifiers.id_sha224.equals(digestAlgOid)) {
        saltSize = 28;
    } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOid)) {
        saltSize = 32;
    } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOid)) {
        saltSize = 48;
    } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOid)) {
        saltSize = 64;
    } else {
        throw new RuntimeException("unknown digest algorithm " + digestAlgOid);
    }

    AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlgOid, DERNull.INSTANCE);
    return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId),
            new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD);
}

From source file:org.xipki.pki.scep.util.ScepUtil.java

License:Open Source License

public static ASN1ObjectIdentifier extractDigesetAlgorithmIdentifier(final String sigOid,
        final byte[] sigParams) throws NoSuchAlgorithmException {
    ParamUtil.requireNonBlank("sigOid", sigOid);

    ASN1ObjectIdentifier algOid = new ASN1ObjectIdentifier(sigOid);

    ASN1ObjectIdentifier digestAlgOid;//from w  ww  .  jav a2s .  co  m
    if (PKCSObjectIdentifiers.md5WithRSAEncryption.equals(algOid)) {
        digestAlgOid = PKCSObjectIdentifiers.md5;
    } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) {
        digestAlgOid = X509ObjectIdentifiers.id_SHA1;
    } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha224;
    } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha256;
    } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha384;
    } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha512;
    } else if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigParams);
        digestAlgOid = param.getHashAlgorithm().getAlgorithm();
    } else {
        throw new NoSuchAlgorithmException("unknown signature algorithm" + algOid.getId());
    }

    return digestAlgOid;
}

From source file:org.xipki.security.P12KeypairGenerator.java

License:Open Source License

private ContentSigner getContentSigner(final PrivateKey key) throws Exception {
    BcContentSignerBuilder builder;/*from   w  ww.j  av  a2s.c o m*/

    if (key instanceof RSAPrivateKey) {
        ASN1ObjectIdentifier hashOid = X509ObjectIdentifiers.id_SHA1;
        ASN1ObjectIdentifier sigOid = PKCSObjectIdentifiers.sha1WithRSAEncryption;

        builder = new BcRSAContentSignerBuilder(buildAlgId(sigOid), buildAlgId(hashOid));
    } else if (key instanceof DSAPrivateKey) {
        ASN1ObjectIdentifier hashOid = X509ObjectIdentifiers.id_SHA1;
        AlgorithmIdentifier sigId = new AlgorithmIdentifier(X9ObjectIdentifiers.id_dsa_with_sha1);

        builder = new BcDSAContentSignerBuilder(sigId, buildAlgId(hashOid));
    } else if (key instanceof ECPrivateKey) {
        ASN1ObjectIdentifier hashOid;
        ASN1ObjectIdentifier sigOid;

        int keySize = ((ECPrivateKey) key).getParams().getOrder().bitLength();
        if (keySize > 384) {
            hashOid = NISTObjectIdentifiers.id_sha512;
            sigOid = X9ObjectIdentifiers.ecdsa_with_SHA512;
        } else if (keySize > 256) {
            hashOid = NISTObjectIdentifiers.id_sha384;
            sigOid = X9ObjectIdentifiers.ecdsa_with_SHA384;
        } else if (keySize > 224) {
            hashOid = NISTObjectIdentifiers.id_sha224;
            sigOid = X9ObjectIdentifiers.ecdsa_with_SHA224;
        } else if (keySize > 160) {
            hashOid = NISTObjectIdentifiers.id_sha256;
            sigOid = X9ObjectIdentifiers.ecdsa_with_SHA256;
        } else {
            hashOid = X509ObjectIdentifiers.id_SHA1;
            sigOid = X9ObjectIdentifiers.ecdsa_with_SHA1;
        }

        builder = new ECDSAContentSignerBuilder(new AlgorithmIdentifier(sigOid), buildAlgId(hashOid));
    } else {
        throw new IllegalArgumentException("unknown type of key " + key.getClass().getName());
    }

    return builder.build(KeyUtil.generatePrivateKeyParameter(key));
}

From source file:org.xwiki.crypto.password.internal.kdf.factory.BcPKCS5S2KeyDerivationFunctionFactory.java

License:Open Source License

private AlgorithmIdentifier toHmacAlgId(AlgorithmIdentifier algorithmIdentifier) {
    ASN1ObjectIdentifier algId = algorithmIdentifier.getAlgorithm();
    AlgorithmIdentifier hmac = null;//from ww w. j a  va2 s .com

    if (algId.equals(X509ObjectIdentifiers.id_SHA1)) {
        hmac = HMAC_SHA1;
    } else if (algId.equals(NISTObjectIdentifiers.id_sha224)) {
        hmac = HMAC_SHA224;
    } else if (algId.equals(NISTObjectIdentifiers.id_sha256)) {
        hmac = HMAC_SHA256;
    } else if (algId.equals(NISTObjectIdentifiers.id_sha384)) {
        hmac = HMAC_SHA384;
    } else if (algId.equals(NISTObjectIdentifiers.id_sha512)) {
        hmac = HMAC_SHA512;
    }
    if (hmac == null) {
        throw new IllegalArgumentException("HMac algorithm not found for digest: " + algId.getId());
    }

    return hmac;
}

From source file:org.xwiki.crypto.password.internal.kdf.factory.BcPKCS5S2KeyDerivationFunctionFactory.java

License:Open Source License

private String toDigestHint(AlgorithmIdentifier algorithmIdentifier) {
    if (algorithmIdentifier == null) {
        return null;
    }/* ww  w  .java  2  s .  c o  m*/

    ASN1ObjectIdentifier algId = algorithmIdentifier.getAlgorithm();
    String hint = null;

    if (algId.equals(HMAC_SHA1.getAlgorithm())) {
        hint = X509ObjectIdentifiers.id_SHA1.getId();
    } else if (algId.equals(HMAC_SHA224.getAlgorithm())) {
        hint = NISTObjectIdentifiers.id_sha224.getId();
    } else if (algId.equals(HMAC_SHA256.getAlgorithm())) {
        hint = NISTObjectIdentifiers.id_sha256.getId();
    } else if (algId.equals(HMAC_SHA384.getAlgorithm())) {
        hint = NISTObjectIdentifiers.id_sha384.getId();
    } else if (algId.equals(HMAC_SHA512.getAlgorithm())) {
        hint = NISTObjectIdentifiers.id_sha512.getId();
    }
    if (hint == null) {
        throw new IllegalArgumentException("Digest hint not found for HMac algorithm: " + algId.getId());
    }

    return hint;
}

From source file:passwdmanager.hig.no.lds.DG_SOD.java

/**
 * Gets the common mnemonic string (such as "SHA1", "SHA256withRSA") given
 * an OID.//w  w w.  j av  a2 s . c o m
 * 
 * @param oid
 *            a BC OID
 * 
 * @throws NoSuchAlgorithmException
 *             if the provided OID is not yet supported
 */
static String lookupMnemonicByOID(DERObjectIdentifier oid) throws NoSuchAlgorithmException {
    if (oid.equals(X509ObjectIdentifiers.organization)) {
        return "O";
    }
    if (oid.equals(X509ObjectIdentifiers.organizationalUnitName)) {
        return "OU";
    }
    if (oid.equals(X509ObjectIdentifiers.commonName)) {
        return "CN";
    }
    if (oid.equals(X509ObjectIdentifiers.countryName)) {
        return "C";
    }
    if (oid.equals(X509ObjectIdentifiers.stateOrProvinceName)) {
        return "ST";
    }
    if (oid.equals(X509ObjectIdentifiers.localityName)) {
        return "L";
    }
    if (oid.equals(X509ObjectIdentifiers.id_SHA1)) {
        return "SHA1";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha224)) {
        return "SHA224";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha256)) {
        return "SHA256";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha384)) {
        return "SHA384";
    }
    if (oid.equals(NISTObjectIdentifiers.id_sha512)) {
        return "SHA512";
    }
    if (oid.equals(PKCS1_SHA1_WITH_RSA_OID)) {
        return "SHA1withRSA";
    }
    if (oid.equals(PKCS1_SHA256_WITH_RSA_OID)) {
        return "SHA256withRSA";
    }
    if (oid.equals(PKCS1_SHA384_WITH_RSA_OID)) {
        return "SHA384withRSA";
    }
    if (oid.equals(PKCS1_SHA512_WITH_RSA_OID)) {
        return "SHA512withRSA";
    }
    if (oid.equals(PKCS1_SHA224_WITH_RSA_OID)) {
        return "SHA224withRSA";
    }
    throw new NoSuchAlgorithmException("Unknown OID " + oid);
}

From source file:passwdmanager.hig.no.lds.DG_SOD.java

static DERObjectIdentifier lookupOIDByMnemonic(String name) throws NoSuchAlgorithmException {
    if (name.equals("O")) {
        return X509ObjectIdentifiers.organization;
    }//w  ww  .  ja  v a  2  s  .  com
    if (name.equals("OU")) {
        return X509ObjectIdentifiers.organizationalUnitName;
    }
    if (name.equals("CN")) {
        return X509ObjectIdentifiers.commonName;
    }
    if (name.equals("C")) {
        return X509ObjectIdentifiers.countryName;
    }
    if (name.equals("ST")) {
        return X509ObjectIdentifiers.stateOrProvinceName;
    }
    if (name.equals("L")) {
        return X509ObjectIdentifiers.localityName;
    }
    if (name.equals("SHA1")) {
        return X509ObjectIdentifiers.id_SHA1;
    }
    if (name.equals("SHA224")) {
        return NISTObjectIdentifiers.id_sha224;
    }
    if (name.equals("SHA256")) {
        return NISTObjectIdentifiers.id_sha256;
    }
    if (name.equals("SHA384")) {
        return NISTObjectIdentifiers.id_sha384;
    }
    if (name.equals("SHA512")) {
        return NISTObjectIdentifiers.id_sha512;
    }
    if (name.equals("SHA1withRSA")) {
        return PKCS1_SHA1_WITH_RSA_OID;
    }
    if (name.equals("SHA256withRSA")) {
        return PKCS1_SHA256_WITH_RSA_OID;
    }
    if (name.equals("SHA384withRSA")) {
        return PKCS1_SHA384_WITH_RSA_OID;
    }
    if (name.equals("SHA512withRSA")) {
        return PKCS1_SHA512_WITH_RSA_OID;
    }
    if (name.equals("SHA224withRSA")) {
        return PKCS1_SHA224_WITH_RSA_OID;
    }
    throw new NoSuchAlgorithmException("Unknown OID " + name);
}

From source file:test.unit.be.fedict.eid.applet.DerTest.java

License:Open Source License

@Test
public void digestInfoSha512() throws Exception {
    byte[] message = "hello world".getBytes();
    MessageDigest messageDigest = MessageDigest.getInstance("SHA-512");
    byte[] digest = messageDigest.digest(message);
    LOG.debug("Digest: " + new String(Hex.encodeHex(digest)));
    DERObjectIdentifier hashAlgoId = NISTObjectIdentifiers.id_sha512;
    DigestInfo digestInfo = new DigestInfo(new AlgorithmIdentifier(hashAlgoId, DERNull.INSTANCE), digest);
    byte[] encodedDigestInfo = digestInfo.getEncoded();
    LOG.debug("Digest Info: " + new String(Hex.encodeHex(encodedDigestInfo)));
}