Skip to content

Commit

Permalink
Explicitly converting String to bytes using UTF-8 charset.
Browse files Browse the repository at this point in the history
  • Loading branch information
william-ferguson-au committed Dec 31, 2013
1 parent b8ac39a commit d428fbd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
23 changes: 22 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<!--
This is to get the sources attached during deploy.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
10 changes: 9 additions & 1 deletion src/main/java/au/com/xandar/crypto/CryptoPacketConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

/**
* Responsible for converting a CryptoPacket into a Base64 String and vice versa.
Expand Down Expand Up @@ -44,7 +46,13 @@ public String convert(CryptoPacket cryptoPacket) throws CryptoException {
}

public CryptoPacket convert(String base64Payload) throws CryptoException {
final byte[] payloadBytes = base64.decode(base64Payload.getBytes());
final byte[] payloadBytes;
try {
payloadBytes = base64.decode(base64Payload.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
// UTF-8 should always be supported.
throw new CryptoException("Could not decode Base64 String", e);
}

final ByteArrayInputStream stream = new ByteArrayInputStream(payloadBytes);
final byte[] encryptedData = readByteArray(stream);
Expand Down

0 comments on commit d428fbd

Please sign in to comment.