Accepting hmac key of all sizes

pull/144/head
aar 2023-10-06 14:57:32 +05:30
parent 0eb57839b9
commit daa2c1ccaa
1 changed files with 8 additions and 9 deletions

View File

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