Search in sources :

Example 1 with KeyTypes

use of org.openecard.crypto.common.KeyTypes in project open-ecard by ecsec.

the class SmartCardCredentialFactory method convertSignatureAlgorithm.

@Nullable
private static SignatureAndHashAlgorithm convertSignatureAlgorithm(SignatureAlgorithms alg) {
    HashAlgorithms hashAlg = alg.getHashAlg();
    KeyTypes keyType = alg.getKeyType();
    short hash;
    if (hashAlg != null) {
        switch(hashAlg) {
            case CKM_SHA_1:
                hash = HashAlgorithm.sha1;
                break;
            case CKM_SHA224:
                hash = HashAlgorithm.sha224;
                break;
            case CKM_SHA256:
                hash = HashAlgorithm.sha256;
                break;
            case CKM_SHA384:
                hash = HashAlgorithm.sha384;
                break;
            case CKM_SHA512:
                hash = HashAlgorithm.sha512;
                break;
            default:
                throw new IllegalArgumentException("Unsupported hash algorithm selected.");
        }
    } else {
        return null;
    }
    short sig;
    switch(keyType) {
        case CKK_RSA:
            sig = SignatureAlgorithm.rsa;
            break;
        case CKK_EC:
            sig = SignatureAlgorithm.ecdsa;
            break;
        default:
            throw new IllegalArgumentException("Unsupported signature algorithm selected.");
    }
    return new SignatureAndHashAlgorithm(hash, sig);
}
Also used : HashAlgorithms(org.openecard.crypto.common.HashAlgorithms) KeyTypes(org.openecard.crypto.common.KeyTypes) SignatureAndHashAlgorithm(org.openecard.bouncycastle.tls.SignatureAndHashAlgorithm) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 SignatureAndHashAlgorithm (org.openecard.bouncycastle.tls.SignatureAndHashAlgorithm)1 HashAlgorithms (org.openecard.crypto.common.HashAlgorithms)1 KeyTypes (org.openecard.crypto.common.KeyTypes)1