Skip to content

Conversation

nchandran10
Copy link

@nchandran10 nchandran10 commented Sep 2, 2024

EncryptionUtils.loadDecryptionKey and EncryptionUtils.loadEncryptionCertificate now supports bytes array for populating respective object along with existing support for filepath.

  • An issue/feature request has been created for this PR
  • Pull Request title clearly describes the work in the pull request and the Pull Request description provides details about how to validate the work. Missing information here may result in a delayed response.
  • File the PR against the main branch
  • The code in this PR is covered by unit tests

Link to issue/feature request:

Description

EncryptionUtils now allow loading Certificate and PrivateKey by passing the data in bytes. Existing functions are still valid and continues to support loading certificate and key using file path.

@jaaufauvre jaaufauvre added the safe The PR has been reviewed by Mastercard and has been validated to be safe label Sep 2, 2024
@karen-avetisyan-mc
Copy link
Contributor

karen-avetisyan-mc commented Sep 2, 2024

What is a use case for this scenario?

/**
* Populate a X509 encryption certificate object with the certificate data at the given certificate data in bytes.
*/
public static Certificate loadEncryptionCertificate(byte[] certificateBytes) throws CertificateException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more flexibility we could use a InputStream instead of a byte[]. This way we can handle data from various sources, files, network, etc.

This is the choice that was made here: https://github.com/Mastercard/oauth1-signer-java/blob/main/src/main/java/com/mastercard/developer/utils/AuthenticationUtils.java#L28

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, with that change, we still have a single interface and better flexibility

/**
* Load a RSA decryption key from key data in bytes.
*/
public static PrivateKey loadDecryptionKey(byte[] keyDataBytes) throws GeneralSecurityException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to add tests to the EncryptionUtilsTest class, all public methods should be tested.

e113028 added 2 commits September 4, 2024 09:26
…byte[] certificateBytes), loadEncryptionCertificate(byte[] certificateBytes)
Copy link
Contributor

@karen-avetisyan-mc karen-avetisyan-mc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@ShimonaR-MC ShimonaR-MC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine

@karen-avetisyan-mc karen-avetisyan-mc merged commit bb115d9 into Mastercard:main Sep 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe The PR has been reviewed by Mastercard and has been validated to be safe

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants