File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
src/main/java/com/mastercard/developer/encryption Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -25,11 +25,22 @@ abstract class EncryptionConfigBuilder {
2525
2626 void computeEncryptionKeyFingerprintWhenNeeded () throws EncryptionException {
2727 try {
28- if (encryptionCertificate == null || !isNullOrEmpty (encryptionKeyFingerprint )) {
29- // No encryption certificate set or key fingerprint already provided
28+ if (( encryptionCertificate == null && encryptionKey == null ) || !isNullOrEmpty (encryptionKeyFingerprint )) {
29+ // No encryption certificate / encryption key set or key fingerprint already provided
3030 return ;
3131 }
32- byte [] keyFingerprintBytes = sha256digestBytes (encryptionCertificate .getPublicKey ().getEncoded ());
32+ final PublicKey publicKey ;
33+ if (encryptionKey != null && encryptionCertificate != null ) {
34+ throw new IllegalArgumentException ("You can only supply either an encryption key or an encryption certificate" );
35+ }
36+ if (encryptionKey != null ) {
37+ publicKey = encryptionKey ;
38+ } else if (encryptionCertificate != null ) {
39+ publicKey = encryptionCertificate .getPublicKey ();
40+ } else {
41+ throw new IllegalArgumentException ("You need to supply either one of the encryption key or the encryption certificate" );
42+ }
43+ byte [] keyFingerprintBytes = sha256digestBytes (publicKey .getEncoded ());
3344 encryptionKeyFingerprint = encodeBytes (keyFingerprintBytes , FieldLevelEncryptionConfig .FieldValueEncoding .HEX );
3445 } catch (Exception e ) {
3546 throw new EncryptionException ("Failed to compute encryption key fingerprint!" , e );
You can’t perform that action at this time.
0 commit comments