From be7349f0b52976f93e4e287b0fd4653a3fbc135d Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 23 Nov 2022 20:07:03 +0100 Subject: [PATCH] Clean up CachingBcPublicKeyDataDecryptorFactory --- .../CachingBcPublicKeyDataDecryptorFactory.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pgpainless-core/src/main/java/org/bouncycastle/CachingBcPublicKeyDataDecryptorFactory.java b/pgpainless-core/src/main/java/org/bouncycastle/CachingBcPublicKeyDataDecryptorFactory.java index 3c967224..510b0938 100644 --- a/pgpainless-core/src/main/java/org/bouncycastle/CachingBcPublicKeyDataDecryptorFactory.java +++ b/pgpainless-core/src/main/java/org/bouncycastle/CachingBcPublicKeyDataDecryptorFactory.java @@ -59,16 +59,20 @@ public class CachingBcPublicKeyDataDecryptorFactory } private byte[] lookupSessionKeyData(byte[][] secKeyData) { - byte[] sk = secKeyData[0]; - String key = Base64.toBase64String(sk); + String key = toKey(secKeyData); byte[] sessionKey = cachedSessionKeys.get(key); return copy(sessionKey); } private void cacheSessionKeyData(byte[][] secKeyData, byte[] sessionKey) { + String key = toKey(secKeyData); + cachedSessionKeys.put(key, copy(sessionKey)); + } + + private static String toKey(byte[][] secKeyData) { byte[] sk = secKeyData[0]; String key = Base64.toBase64String(sk); - cachedSessionKeys.put(key, copy(sessionKey)); + return key; } private static byte[] copy(byte[] bytes) {