Accepting hmac key of all sizes

pull/144/head
aar 2023-10-05 14:33:24 +05:30
parent 5ef39534ec
commit 0eb57839b9
1 changed files with 9 additions and 12 deletions

View File

@ -245,19 +245,16 @@ public final class JoseUtils {
}
var size = macKey.getEncoded().length * 8;
switch (size) {
case 256:
return AlgorithmIdentifiers.HMAC_SHA256;
case 384:
return AlgorithmIdentifiers.HMAC_SHA384;
case 512:
if (size >= 256) {
if (size >= 512) {
return AlgorithmIdentifiers.HMAC_SHA512;
default:
throw new IllegalArgumentException("Bad key size: " + size);
} else if (size >= 384) {
return AlgorithmIdentifiers.HMAC_SHA384;
} else {
return AlgorithmIdentifiers.HMAC_SHA256;
}
} else {
throw new IllegalArgumentException("Bad key size: " + size);
}
}
}