Skip to content

Commit e12a239

Browse files
BRIAN HOLYFIELDBRIAN HOLYFIELD
authored andcommitted
Update to KeyCode Encoding Logic
Update to KeyCode Encoding Logic
1 parent 6d81ce3 commit e12a239

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

SendSafelyAPI/src/com/sendsafely/handlers/CreatePackageHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ protected Package convert(CreatePackageResponse obj) throws CreatePackageFailedE
8282
try
8383
{
8484
Package info = getPackageInformation(obj);
85-
String b64String = CryptoUtil.GenerateKeyCode();
86-
String decodedString = DatatypeConverter.printBase64Binary(b64String.getBytes());
87-
info.setKeyCode(new String(UrlBase64.encode(decodedString.getBytes())));
85+
info.setKeyCode(CryptoUtil.GenerateKeyCode());
8886
return info;
8987
}
9088
catch (TokenGenerationFailedException e)

SendSafelyAPI/src/com/sendsafely/utils/CryptoUtil.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import javax.xml.bind.DatatypeConverter;
1515

1616
import com.sendsafely.exceptions.PublicKeyEncryptionFailedException;
17+
1718
import org.bouncycastle.bcpg.ArmoredOutputStream;
1819
import org.bouncycastle.crypto.AsymmetricBlockCipher;
1920
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
@@ -26,15 +27,6 @@
2627
import org.bouncycastle.crypto.util.PrivateKeyFactory;
2728
import org.bouncycastle.crypto.util.PublicKeyFactory;
2829
import org.bouncycastle.openpgp.*;
29-
import org.bouncycastle.openpgp.PGPCompressedData;
30-
import org.bouncycastle.openpgp.PGPEncryptedDataGenerator;
31-
import org.bouncycastle.openpgp.PGPEncryptedDataList;
32-
import org.bouncycastle.openpgp.PGPException;
33-
import org.bouncycastle.openpgp.PGPLiteralData;
34-
import org.bouncycastle.openpgp.PGPLiteralDataGenerator;
35-
import org.bouncycastle.openpgp.PGPObjectFactory;
36-
import org.bouncycastle.openpgp.PGPPBEEncryptedData;
37-
import org.bouncycastle.openpgp.PGPUtil;
3830
import org.bouncycastle.openpgp.operator.PBEDataDecryptorFactory;
3931
import org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator;
4032
import org.bouncycastle.openpgp.operator.PublicKeyKeyEncryptionMethodGenerator;
@@ -43,11 +35,13 @@
4335
import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
4436
import org.bouncycastle.util.encoders.Base64;
4537
import org.bouncycastle.util.encoders.Hex;
38+
import org.bouncycastle.util.encoders.UrlBase64;
4639

4740
import com.sendsafely.exceptions.MessageException;
4841
import com.sendsafely.exceptions.PublicKeyDecryptionFailedException;
4942
import com.sendsafely.exceptions.SignatureCreationFailedException;
5043
import com.sendsafely.exceptions.TokenGenerationFailedException;
44+
5145
import org.bouncycastle.util.io.Streams;
5246

5347
public class CryptoUtil
@@ -91,8 +85,7 @@ public static String GenerateKeyCode() throws TokenGenerationFailedException
9185
} catch (NoSuchProviderException e) {
9286
throw new TokenGenerationFailedException(e);
9387
}
94-
95-
return DatatypeConverter.printBase64Binary(randomBytes);
88+
return new String(UrlBase64.encode(randomBytes)).replace(".", "");
9689
}
9790

9891
public static String PBKDF2(String token, String salt, int iterations)

0 commit comments

Comments
 (0)