mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 11:49:25 +00:00
Document encryption key
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user