Skip to content
This repository has been archived by the owner on Nov 18, 2018. It is now read-only.

Commit

Permalink
Updating aerogear-crypto to version 0.1.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
danbev committed Aug 28, 2014
1 parent 412aea9 commit 4d8d276
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<groupId>org.jboss.aerogear</groupId>
<artifactId>aerogear-crypto</artifactId>
</dependency>
<dependency>
<groupId>bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
*/
package org.jboss.aerogear.simplepush.util;

import org.bouncycastle.util.encoders.UrlBase64;
import org.jboss.aerogear.AeroGearCrypto;
import org.jboss.aerogear.crypto.BlockCipher;
import org.jboss.aerogear.crypto.CryptoBox;
import org.jboss.aerogear.crypto.encoders.UrlBase64;

import java.net.URLDecoder;
import java.net.URLEncoder;
Expand Down Expand Up @@ -45,7 +45,7 @@ private CryptoUtil() {
public static String encrypt(final byte[] key, final String content) throws Exception {
final byte[] iv = BlockCipher.getIV();
final byte[] encrypted = new CryptoBox(key).encrypt(iv, content.getBytes(ASCII));
final String base64 = new String(UrlBase64.encode(prependIV(encrypted, iv)));
final String base64 = new UrlBase64().encode(prependIV(encrypted, iv));
return URLEncoder.encode(base64, ASCII.displayName());
}

Expand All @@ -67,7 +67,7 @@ private static byte[] prependIV(final byte[] target, final byte[] iv) {
* @throws Exception
*/
public static String decrypt(final byte[] key, final String content) throws Exception {
final byte[] decodedContent = UrlBase64.decode(URLDecoder.decode(content, ASCII.displayName()));
final byte[] decodedContent = new UrlBase64().decode(URLDecoder.decode(content, ASCII.displayName()));
final byte[] iv = extractIV(decodedContent);
final byte[] decrypted = new CryptoBox(key).decrypt(iv, extractContent(decodedContent));
return new String(decrypted, ASCII);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CryptoUtilTest {
public void encrypt() throws Exception {
final byte[] salt = "some salt for the server private".getBytes();
final byte[] key = CryptoUtil.secretKey("key", salt);
final String encrypted = CryptoUtil.encrypt(key, "some string to endrypt");
final String encrypted = CryptoUtil.encrypt(key, "some string to encrypt");
assertThat(encrypted, is(notNullValue()));
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<aerogear.crypto.version>0.1.2</aerogear.crypto.version>
<aerogear.crypto.version>0.1.5</aerogear.crypto.version>
<bouncycastle.version>140</bouncycastle.version>
<h2database.version>1.3.172</h2database.version>
<commons.http.core.version>4.2.4</commons.http.core.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.HashSet;
import java.util.Set;

import org.jboss.aerogear.crypto.Random;
import org.jboss.aerogear.crypto.RandomUtils;
import org.jboss.aerogear.simplepush.protocol.Ack;
import org.jboss.aerogear.simplepush.protocol.AckMessage;
import org.jboss.aerogear.simplepush.protocol.HelloMessage;
Expand Down Expand Up @@ -171,7 +171,7 @@ public SimplePushServerConfig config() {
public static byte[] generateAndStorePrivateKey(final DataStore store, final SimplePushServerConfig config) {
byte[] keySalt = store.getPrivateKeySalt();
if (keySalt.length == 0) {
keySalt = new Random().randomBytes();
keySalt = RandomUtils.randomBytes();
store.savePrivateKeySalt(keySalt);
}
return CryptoUtil.secretKey(config.password(), keySalt);
Expand Down

0 comments on commit 4d8d276

Please sign in to comment.