-
Notifications
You must be signed in to change notification settings - Fork 83
EncryptionUtils - added support for passing key and certificate as bytes array #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… along with existing support.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
…byte[] certificateBytes), loadEncryptionCertificate(byte[] certificateBytes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine
EncryptionUtils.loadDecryptionKey and EncryptionUtils.loadEncryptionCertificate now supports bytes array for populating respective object along with existing support for filepath.
main
branchLink 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.