Skip to content
Merged
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
@@ -1,7 +1,9 @@
package com.codemonkeylabs.encryptionexample.app;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
Expand Down Expand Up @@ -120,7 +122,7 @@ private void decryptButton()

//set up your streams for decryption
ByteArrayInputStream encInputStream = new ByteArrayInputStream(Base64.decode(encText.toCharArray()));
ByteArrayOutputStream plainTextOutputStream = new ByteArrayOutputStream(1024 * 100);
ByteArrayOutputStream plainTextOutputStream = new ByteArrayOutputStream(1024 * 10);
String unencryptedString = "";

//main aes decrypt function
Expand Down Expand Up @@ -156,26 +158,48 @@ private void clearButton()

private void encryptButton()
{
String inputtedUnencryptedText = this.inputtedUnencryptedText.getText().toString();
ByteArrayInputStream plainTextInputStream;
final String inputtedUnencryptedText = this.inputtedUnencryptedText.getText().toString();

//sanity check on input
if (TextUtils.isEmpty(inputtedUnencryptedText))
{
return;
}

new AsyncTask<String, Integer, String>(){

@Override
protected String doInBackground(String... params)
{
return encryptString(inputtedUnencryptedText);
}

@Override
protected void onPostExecute(String encryptedString)
{
super.onPostExecute(encryptedString);
if (encryptedString == null) return;
encryptedText.setText(encryptedString);
}
}.execute();

}

@Nullable
private String encryptString(String inputtedUnencryptedText)
{
ByteArrayInputStream plainTextInputStream;
try
{
//create an inputstream from a string
plainTextInputStream = new ByteArrayInputStream(inputtedUnencryptedText.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e)
{
Log.e(EncryptionActivity.class.getName(), e.getMessage(), e);
return;
return null;
}

ByteArrayOutputStream encOutputStream = new ByteArrayOutputStream(1024 * 100);
ByteArrayOutputStream encOutputStream = new ByteArrayOutputStream(1024 * 10);

//main aes encrypt
byte[] iv = AESEncryptDecrypt.aesEncrypt(plainTextInputStream,
Expand All @@ -192,8 +216,7 @@ private void encryptButton()

//set ui textview to encrypted base64 encoded value
String encryptedString = new String(Base64.encode(encOutputStream.toByteArray()));
this.encryptedText.setText(encryptedString);

return encryptedString;
}

}