Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

/**
* AES Helper Encryption Class
* Created by brianplummer on 4/29/14.
*/
public class AESEncryptDecrypt {

Expand Down Expand Up @@ -64,7 +63,8 @@ public static void setProvider(Provider provider, String providerName) {
public enum AESCipherType {
AES_CIPHER_CTR_NOPADDING("AES/CTR/NOPADDING"),
AES_CIPHER_ECB_PKCS5PADDING("AES/ECB/PKCS5PADDING"),
AES_CBC_PKCS5PADDING("AES/CBC/PKCS5Padding");
AES_CBC_PKCS5PADDING("AES/CBC/PKCS5Padding"),
AES_CBC_PKCS7Padding("AES/CBC/PKCS7Padding");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import javax.crypto.Cipher;
/**
* RSA Helper Encryption Class
* Created by brianplummer on 4/29/14.
*/
public class RSAEncryptDecrypt {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
package com.codemonkeylabs.encryptionsexample;

import android.test.InstrumentationTestCase;

import com.codemonkeylabs.encryptionexample.app.AESEncryptDecrypt;
import com.codemonkeylabs.encryptionexample.app.RSAEncryptDecrypt;
import com.codemonkeylabs.encryptionexample.app.Util;

import org.apache.commons.io.IOUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.security.KeyPair;
import java.util.Arrays;

/**
* Created by brianplummer on 9/2/14.
*/
import static org.junit.Assert.assertTrue;

public class EncryptionTest
{
private String testText = null;
Expand Down Expand Up @@ -79,6 +70,34 @@ public void testAESEncryptionCBC() throws UnsupportedEncodingException
}


@Test
public void testAESEncryptionCBCPadding7() throws UnsupportedEncodingException
{

ByteArrayInputStream plainTextInputStream = new ByteArrayInputStream(testText.getBytes("UTF-8"));
ByteArrayOutputStream encOutputStream = new ByteArrayOutputStream(1024 * 100);

byte[] iv = AESEncryptDecrypt.aesEncrypt(plainTextInputStream,
AESEncryptDecrypt.NOT_SECRET_ENCRYPTION_KEY.toCharArray(),
AESEncryptDecrypt.AESCipherType.AES_CBC_PKCS7Padding,
encOutputStream);


ByteArrayInputStream encInputStream = new ByteArrayInputStream(encOutputStream.toByteArray());
ByteArrayOutputStream plainTextOutputStream = new ByteArrayOutputStream(1024 * 100);

AESEncryptDecrypt.aesDecrypt(encInputStream,
AESEncryptDecrypt.NOT_SECRET_ENCRYPTION_KEY.toCharArray(),
iv,
AESEncryptDecrypt.AESCipherType.AES_CBC_PKCS7Padding,
plainTextOutputStream);


String unencryptedString = new String(plainTextOutputStream.toByteArray(),"UTF-8");

assertTrue(unencryptedString.startsWith("All this while Tashtego, Daggoo, and Queequeg"));
}

@Test
public void testAESEncryptionCTR() throws UnsupportedEncodingException
{
Expand Down