Document encryption key

This commit is contained in:
2026-01-12 17:49:28 +01:00
parent 68e3a29268
commit c4a9c5fddd
3 changed files with 21 additions and 3 deletions

View File

@@ -126,7 +126,7 @@ public class OAuthTokenCipher {
}
private static SecretKey decodeKey(String base64Key, String source) {
byte[] decoded = Base64.getDecoder().decode(base64Key);
byte[] decoded = decodeBase64(base64Key, source);
if (decoded.length != 32) {
throw new IllegalArgumentException(
source + " must be a base64-encoded 256-bit (32 byte) key"
@@ -134,4 +134,20 @@ public class OAuthTokenCipher {
}
return new SecretKeySpec(decoded, "AES");
}
private static byte[] decodeBase64(String base64Key, String source) {
try {
return Base64.getDecoder().decode(base64Key);
} catch (IllegalArgumentException ex) {
try {
return Base64.getUrlDecoder().decode(base64Key);
} catch (IllegalArgumentException urlEx) {
ex.addSuppressed(urlEx);
throw new IllegalArgumentException(
source + " must be a base64-encoded 256-bit (32 byte) key",
ex
);
}
}
}
}