Skip to content

Commit 06aee39

Browse files
chenkinsdkocher
authored andcommitted
Using Base64 url encoder for seeds and kdf salt.
1 parent d38b1b8 commit 06aee39

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

hub/src/main/java/cloud/katta/crypto/uvf/UvfMetadataPayload.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.openapitools.jackson.nullable.JsonNullableModule;
1919

2020
import java.net.URI;
21+
import java.nio.charset.StandardCharsets;
2122
import java.security.NoSuchAlgorithmException;
2223
import java.security.spec.InvalidKeySpecException;
2324
import java.text.ParseException;
@@ -29,8 +30,6 @@
2930
import java.util.UUID;
3031
import java.util.stream.Collectors;
3132

32-
import static cloud.katta.crypto.KeyHelper.decodePrivateKey;
33-
3433
import cloud.katta.crypto.exceptions.NotECKeyException;
3534
import cloud.katta.model.JWEPayload;
3635
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -51,7 +50,8 @@
5150
import com.nimbusds.jose.jwk.JWKSet;
5251
import com.nimbusds.jose.jwk.OctetSequenceKey;
5352
import com.nimbusds.jose.jwk.gen.OctetSequenceKeyGenerator;
54-
import com.nimbusds.jose.util.Base64URL;
53+
54+
import static cloud.katta.crypto.KeyHelper.decodePrivateKey;
5555

5656
/**
5757
* Represents payload of <a href="https://github.com/encryption-alliance/unified-vault-format/blob/develop/vault%20metadata/README.md"><code>vault.uvf</code> metadata</a>.
@@ -101,7 +101,7 @@ public String toJSON() throws JsonProcessingException {
101101
}
102102

103103
public static UvfMetadataPayload create() {
104-
final String kid = Base64URL.encode(new AlphanumericRandomStringService(4).random()).toString();
104+
final String kid = Base64.getUrlEncoder().encodeToString(new AlphanumericRandomStringService(4).random().getBytes(StandardCharsets.UTF_8));
105105
final byte[] rawSeed = new byte[32];
106106
FastSecureRandomProvider.get().provide().nextBytes(rawSeed);
107107
final byte[] kdfSalt = new byte[32];
@@ -110,12 +110,12 @@ public static UvfMetadataPayload create() {
110110
.withFileFormat("AES-256-GCM-32k")
111111
.withNameFormat("AES-SIV-512-B64URL")
112112
.withSeeds(new HashMap<String, String>() {{
113-
put(kid, Base64.getEncoder().encodeToString(rawSeed));
113+
put(kid, Base64.getUrlEncoder().encodeToString(rawSeed));
114114
}})
115115
.withLatestSeed(kid)
116116
.withinitialSeed(kid)
117117
.withKdf("HKDF-SHA512")
118-
.withKdfSalt(Base64.getEncoder().encodeToString(kdfSalt));
118+
.withKdfSalt(Base64.getUrlEncoder().encodeToString(kdfSalt));
119119
}
120120

121121
public String computeRootDirIdHash() throws JsonProcessingException {

hub/src/test/java/cloud/katta/crypto/uvf/UvfMetadataPayloadTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public void encryptDecrypt() throws JOSEException, JsonProcessingException, Pars
7979
final byte[] rawMasterKey = new byte[32];
8080
FastSecureRandomProvider.get().provide().nextBytes(rawMasterKey);
8181
final HashMap<String, String> keys = new HashMap<String, String>() {{
82-
put("key01", Base64URL.encode(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)).toString());
83-
put("key02", Base64URL.encode(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)).toString());
82+
put("key01", Base64.getUrlEncoder().encodeToString(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)).toString());
83+
put("key02", Base64.getUrlEncoder().encodeToString(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)).toString());
8484
}};
8585
final UvfMetadataPayload orig = new UvfMetadataPayload()
8686
.withFileFormat("AES-256-GCM-32k")

0 commit comments

Comments
 (0)