Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,23 @@ void decryptWithPublicKeyThrowsException() throws Exception {
ecies.decrypt(testPublicKeysetHandle, cipherText, CONTEXT_INFO)
);
}

@Test
void generateAndStorePublicKeyWritesPublicKeysetNotPrivateKeyset() throws Exception {
File keysetFile = new File(tempDir, "public-keyset-verification.json");
assertFalse(keysetFile.exists());

ecies.generateAndStorePublicKey(testPrivateKeysetHandle, keysetFile);

KeysetHandle loadedKeyset = ecies.loadPublicKey(keysetFile);

// The stored keyset must be a public keyset: it can encrypt but NOT decrypt.
// If the private keyset were written instead, decryption would succeed.
byte[] cipherText = ecies.encrypt(loadedKeyset, INITIAL_TEXT, CONTEXT_INFO);

assertThrows(GeneralSecurityException.class, () ->
ecies.decrypt(loadedKeyset, cipherText, CONTEXT_INFO),
"Loaded keyset must be public-only: decryption must fail"
);
}
}