You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The class ASAPCryptoAlgorithms is missing a useful method for encrypting bytes using asymmetric encryption without using the encrypted message.
Here is an example implementation:
/** * Uses asymmetric encryption to encrypt the unencryptedBytes using the public key of the recipient. * @param unencryptedBytes bytes to encrypt * @param recipient identifier of the recipient * @param ASAPKeyStore key store that holds the public key of the recipient * @return encrypted bytes * @throws ASAPSecurityException if the public key is missing or other problems occurred during encryption */publicstaticbyte[] encryptAsymmetric(byte[] unencryptedBytes, CharSequencerecipient, ASAPKeyStoreASAPKeyStore) throwsASAPSecurityException {
PublicKeypublicKey = ASAPKeyStore.getPublicKey(recipient);
if (publicKey == null) {
thrownewASAPSecurityException("recipients' public key cannot be found");
} else {
try {
Ciphercipher = Cipher.getInstance(ASAPKeyStore.getAsymmetricEncryptionAlgorithm());
cipher.init(1, publicKey);
returncipher.doFinal(unencryptedBytes);
} catch (InvalidKeyException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException |
NoSuchAlgorithmExceptione) {
thrownewASAPSecurityException("problems when encrypting", e);
}
}
}
The text was updated successfully, but these errors were encountered:
The class
ASAPCryptoAlgorithms
is missing a useful method for encrypting bytes using asymmetric encryption without using the encrypted message.Here is an example implementation:
The text was updated successfully, but these errors were encountered: