Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit bdda6cb

Browse files
authored
feat(encryption): allow custom loading of JWK sets (#214)
* allow custom loading of JWK sets
1 parent ec3ccab commit bdda6cb

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/main/java/com/hyperwallet/clientsdk/util/HyperwalletEncryption.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public HyperwalletEncryption(JWEAlgorithm encryptionAlgorithm, JWSAlgorithm sign
106106

107107
public String encrypt(String body) throws JOSEException, IOException, ParseException {
108108

109-
JWK clientPrivateKey = getKeyByAlgorithm(loadKeySet(clientPrivateKeySetLocation), signAlgorithm);
110-
JWK hyperwalletPublicKey = getKeyByAlgorithm(loadKeySet(hyperwalletKeySetLocation), encryptionAlgorithm);
109+
JWK clientPrivateKey = getKeyByAlgorithm(loadClientPrivateKeySet(), signAlgorithm);
110+
JWK hyperwalletPublicKey = getKeyByAlgorithm(loadHyperwalletKeySet(), encryptionAlgorithm);
111111
JWSSigner jwsSigner = getJWSSigner(clientPrivateKey);
112112
JWEEncrypter jweEncrypter = getJWEEncrypter(hyperwalletPublicKey);
113113

@@ -132,8 +132,8 @@ public String encrypt(String body) throws JOSEException, IOException, ParseExcep
132132

133133
public String decrypt(String body) throws ParseException, IOException, JOSEException {
134134

135-
JWK privateKeyToDecrypt = getKeyByAlgorithm(loadKeySet(clientPrivateKeySetLocation), encryptionAlgorithm);
136-
JWK publicKeyToSign = getKeyByAlgorithm(loadKeySet(hyperwalletKeySetLocation), signAlgorithm);
135+
JWK privateKeyToDecrypt = getKeyByAlgorithm(loadClientPrivateKeySet(), encryptionAlgorithm);
136+
JWK publicKeyToSign = getKeyByAlgorithm(loadHyperwalletKeySet(), signAlgorithm);
137137
JWEDecrypter jweDecrypter = getJWEDecrypter(privateKeyToDecrypt);
138138
JWSVerifier jwsVerifier = getJWSVerifier(publicKeyToSign);
139139

@@ -148,6 +148,20 @@ public String decrypt(String body) throws ParseException, IOException, JOSEExcep
148148
return jwsObject.getPayload().toString();
149149
}
150150

151+
/**
152+
* Allows clients to implement a custom loading of their private JWK set.
153+
*/
154+
protected JWKSet loadClientPrivateKeySet() throws IOException, ParseException {
155+
return loadKeySet(clientPrivateKeySetLocation);
156+
}
157+
158+
/**
159+
* Allows clients to implement a custom loading of Hyperwallet public JWK set.
160+
*/
161+
protected JWKSet loadHyperwalletKeySet() throws IOException, ParseException {
162+
return loadKeySet(hyperwalletKeySetLocation);
163+
}
164+
151165
public void verifySignatureExpirationDate(Object signatureExpirationDate) {
152166
if (signatureExpirationDate == null) {
153167
throw new HyperwalletException("exp JWS header param was null");
@@ -389,4 +403,4 @@ public HyperwalletEncryption build() {
389403
return hyperwalletEncryption;
390404
}
391405
}
392-
}
406+
}

0 commit comments

Comments
 (0)