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);
}
Aggregations