Skip to content

Commit 32fc48b

Browse files
committed
PGPEncryptedDataGenerator: Allow extraction of session-key
1 parent 797bbf5 commit 32fc48b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pg/src/main/java/org/bouncycastle/openpgp/PGPEncryptedDataGenerator.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public class PGPEncryptedDataGenerator
8989
// If true, force generation of a session key, even if we only have a single password-based encryption method
9090
// and could therefore use the S2K output as session key directly.
9191
private boolean forceSessionKey = true;
92+
private SessionKeyExtractionCallback sessionKeyExtractionCallback = null;
9293

9394
/**
9495
* Base constructor.
@@ -178,6 +179,11 @@ private byte[] createSessionInfo(
178179
return sessionInfo;
179180
}
180181

182+
public void setSessionKeyExtractionCallback(SessionKeyExtractionCallback callback)
183+
{
184+
this.sessionKeyExtractionCallback = callback;
185+
}
186+
181187
/**
182188
* Create an OutputStream based on the configured methods.
183189
* <p>
@@ -252,6 +258,11 @@ else if (directS2K)
252258
messageKey = sessionKey;
253259
}
254260

261+
if (sessionKeyExtractionCallback != null)
262+
{
263+
sessionKeyExtractionCallback.extractSessionKey(new PGPSessionKey(defAlgorithm, sessionKey));
264+
}
265+
255266
PGPDataEncryptor dataEncryptor = dataEncryptorBuilder.build(messageKey);
256267
digestCalc = dataEncryptor.getIntegrityCalculator();
257268

@@ -579,4 +590,9 @@ public void close()
579590
this.finish();
580591
}
581592
}
593+
594+
public interface SessionKeyExtractionCallback
595+
{
596+
void extractSessionKey(PGPSessionKey sessionKey);
597+
}
582598
}

0 commit comments

Comments
 (0)