Search in sources :

Example 76 with ASN1ObjectIdentifier

use of org.openecard.bouncycastle.asn1.ASN1ObjectIdentifier in project xipki by xipki.

the class AlgorithmUtil method getSigAlgId.

// method getMacAlgId
public static AlgorithmIdentifier getSigAlgId(String sigAlgName) throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("sigAlgName", sigAlgName);
    String algoS = sigAlgName.toUpperCase();
    algoS = canonicalizeAlgoText(algoS);
    AlgorithmIdentifier signatureAlgId;
    if (algoS.contains("MGF1")) {
        HashAlgo ha = mgf1SigNameToDigestOidMap.get(algoS);
        if (ha == null) {
            throw new NoSuchAlgorithmException("unknown algorithm " + algoS);
        }
        signatureAlgId = buildRSAPSSAlgId(ha);
    } else {
        ASN1ObjectIdentifier algOid = sigAlgNameToOidMap.get(algoS);
        if (algOid == null) {
            throw new NoSuchAlgorithmException("unknown algorithm " + algoS);
        }
        boolean withNullParam = algoS.contains("RSA");
        signatureAlgId = withNullParam ? new AlgorithmIdentifier(algOid, DERNull.INSTANCE) : new AlgorithmIdentifier(algOid);
    }
    return signatureAlgId;
}
Also used : HashAlgo(org.xipki.security.HashAlgo) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 77 with ASN1ObjectIdentifier

use of org.openecard.bouncycastle.asn1.ASN1ObjectIdentifier in project xipki by xipki.

the class AlgorithmUtil method extractHashAlgoFromMacAlg.

// method getECDSASigAlgId
public static HashAlgo extractHashAlgoFromMacAlg(AlgorithmIdentifier macAlg) {
    ASN1ObjectIdentifier oid = macAlg.getAlgorithm();
    HashAlgo hashAlgo = macAlgOidToDigestMap.get(oid);
    if (hashAlgo == null) {
        throw new IllegalArgumentException("unknown algorithm identifier " + oid.getId());
    }
    return hashAlgo;
}
Also used : HashAlgo(org.xipki.security.HashAlgo) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 78 with ASN1ObjectIdentifier

use of org.openecard.bouncycastle.asn1.ASN1ObjectIdentifier in project xipki by xipki.

the class AlgorithmUtil method isPlainECDSASigAlg.

// CHECKSTYLE:SKIP
public static boolean isPlainECDSASigAlg(AlgorithmIdentifier algId) {
    ParamUtil.requireNonNull("algId", algId);
    ASN1ObjectIdentifier oid = algId.getAlgorithm();
    if (BSIObjectIdentifiers.ecdsa_plain_SHA1.equals(oid) || BSIObjectIdentifiers.ecdsa_plain_SHA224.equals(oid) || BSIObjectIdentifiers.ecdsa_plain_SHA256.equals(oid) || BSIObjectIdentifiers.ecdsa_plain_SHA384.equals(oid) || BSIObjectIdentifiers.ecdsa_plain_SHA512.equals(oid)) {
        return true;
    }
    return false;
}
Also used : ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 79 with ASN1ObjectIdentifier

use of org.openecard.bouncycastle.asn1.ASN1ObjectIdentifier in project xipki by xipki.

the class AlgorithmUtil method getMacAlgId.

public static AlgorithmIdentifier getMacAlgId(String macAlgName) throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("macAlgName", macAlgName);
    String algoS = macAlgName.toUpperCase();
    algoS = canonicalizeAlgoText(algoS);
    ASN1ObjectIdentifier oid = macAlgNameToOidMap.get(algoS);
    if (oid == null) {
        throw new NoSuchAlgorithmException("unsupported signature algorithm " + algoS);
    }
    return new AlgorithmIdentifier(oid, DERNull.INSTANCE);
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 80 with ASN1ObjectIdentifier

use of org.openecard.bouncycastle.asn1.ASN1ObjectIdentifier in project xipki by xipki.

the class AlgorithmUtil method getRSASigAlgId.

// CHECKSTYLE:SKIP
private static AlgorithmIdentifier getRSASigAlgId(HashAlgo hashAlgo, boolean mgf1) throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("hashAlgo", hashAlgo);
    if (mgf1) {
        return buildRSAPSSAlgId(hashAlgo);
    }
    ASN1ObjectIdentifier sigAlgOid = digestToRSASigAlgMap.get(hashAlgo);
    if (sigAlgOid == null) {
        throw new NoSuchAlgorithmException("unsupported hash " + hashAlgo + " for RSA key");
    }
    return new AlgorithmIdentifier(sigAlgOid, DERNull.INSTANCE);
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Aggregations

ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)327 IOException (java.io.IOException)76 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)70 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)53 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)49 DEROctetString (org.bouncycastle.asn1.DEROctetString)48 DERIA5String (org.bouncycastle.asn1.DERIA5String)47 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)44 DERSequence (org.bouncycastle.asn1.DERSequence)41 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)38 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)36 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)35 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)35 Extension (org.bouncycastle.asn1.x509.Extension)33 ASN1String (org.bouncycastle.asn1.ASN1String)31 HashSet (java.util.HashSet)30 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)29 ArrayList (java.util.ArrayList)28 DirectoryString (org.bouncycastle.asn1.x500.DirectoryString)27 X500Name (org.bouncycastle.asn1.x500.X500Name)27