From f46790be00dfc482e940ea7d4e8a970a3e2cb13a Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 12 Jul 2023 16:49:38 +0200 Subject: [PATCH] Require UTF8 for KeyRingBuilder.addUserId(byte[]) --- .../java/org/pgpainless/key/generation/KeyRingBuilder.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java index a5263391..c9dfdb5c 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java @@ -6,7 +6,6 @@ package org.pgpainless.key.generation; import java.io.IOException; -import java.nio.charset.Charset; import java.security.InvalidAlgorithmParameterException; import java.security.KeyPair; import java.security.KeyPairGenerator; @@ -36,6 +35,7 @@ import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor; import org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor; import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder; import org.bouncycastle.openpgp.operator.PGPDigestCalculator; +import org.bouncycastle.util.Strings; import org.pgpainless.PGPainless; import org.pgpainless.algorithm.HashAlgorithm; import org.pgpainless.algorithm.KeyFlag; @@ -56,9 +56,6 @@ public class KeyRingBuilder implements KeyRingBuilderInterface { private static final long YEAR_IN_SECONDS = 1000L * 60 * 60 * 24 * 365; - @SuppressWarnings("CharsetObjectCanBeUsed") - private final Charset UTF8 = Charset.forName("UTF-8"); - private KeySpec primaryKeySpec; private final List subkeySpecs = new ArrayList<>(); private final Map userIds = new LinkedHashMap<>(); @@ -95,7 +92,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface { @Override public KeyRingBuilder addUserId(@Nonnull byte[] userId) { - return addUserId(new String(userId, UTF8)); + return addUserId(Strings.fromUTF8ByteArray(userId)); } @Override