Skip to content

Commit

Permalink
Merge pull request #6 from rhayes2/Base64CharSupport
Browse files Browse the repository at this point in the history
Base64 char support
  • Loading branch information
rhayes2 committed Jan 3, 2019
2 parents 3f1ecf6 + fa5e68c commit 64bdbbc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,17 @@ private static byte[] encodeMessage(int[] integer_pixel_array, int image_columns
*/
public static List<Bitmap> encodeMessage(List<Bitmap> splitted_images,
String encrypted_message, ProgressHandler progressHandler) {

//Making result method

List<Bitmap> result = new ArrayList<Bitmap>(splitted_images.size());


//Adding start and end message constants to the encrypted message
encrypted_message += END_MESSAGE_COSTANT;
encrypted_message = encrypted_message + END_MESSAGE_COSTANT;
encrypted_message = START_MESSAGE_COSTANT + encrypted_message;


//getting byte array from string
byte[] byte_encrypted_message = encrypted_message.getBytes(Charset.forName("ISO-8859-1"));

Expand Down Expand Up @@ -205,17 +209,19 @@ private static void decodeMessage(byte[] byte_pixel_array, int image_columns,

byte tmp = 0x00;


for (int i = 0; i < byte_pixel_array.length; i++) {


//get last two bits from byte_pixel_array
tmp = (byte) (tmp | ((byte_pixel_array[i] << toShift[shiftIndex
% toShift.length]) & andByte[shiftIndex++ % toShift.length]));

if (shiftIndex % toShift.length == 0) {

//adding temp byte value
byte_encrypted_message.addElement(Byte.valueOf(tmp));


//converting byte value to string
byte[] nonso = {(byte_encrypted_message.elementAt(byte_encrypted_message.size() - 1)).byteValue()};
String str = new String(nonso, Charset.forName("ISO-8859-1"));
Expand All @@ -230,7 +236,10 @@ private static void decodeMessage(byte[] byte_pixel_array, int image_columns,
for (int index = 0; index < temp.length; index++)
temp[index] = byte_encrypted_message.get(index);


String stra = new String(temp, Charset.forName("ISO-8859-1"));


messageDecodingStatus.setMessage(stra.substring(0, stra.length() - 1));
//end fixing

Expand Down Expand Up @@ -281,7 +290,6 @@ public static String decodeMessage(List<Bitmap> encodedImages) {
MessageDecodingStatus messageDecodingStatus = new MessageDecodingStatus();

for (Bitmap bit : encodedImages) {

int[] pixels = new int[bit.getWidth() * bit.getHeight()];

bit.getPixels(pixels, 0, bit.getWidth(), 0, 0, bit.getWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,14 @@ public ImageSteganography(String message, String secret_key, Bitmap image) {
this.message = message;
this.secret_key = convertKeyTo128bit(secret_key);
this.image = image;
try {
/*try {
this.encrypted_zip = Zipping.compress(message);
} catch (Exception e) {
e.printStackTrace();
}
try {
this.encrypted_message = encryptMessage(new String(getEncrypted_zip(), "ISO-8859-1"), this.secret_key);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} */

this.encrypted_zip = message.getBytes();
this.encrypted_message = encryptMessage(message, this.secret_key);

this.encoded = false;
this.decoded = false;
Expand Down Expand Up @@ -137,7 +135,6 @@ public void setSecretKeyWrong(Boolean secretKeyWrong) {
}

public static String encryptMessage(String message, String secret_key){

Log.d(TAG, "Message : " + message );

String encrypted_message = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected void onPostExecute(ImageSteganography imageSteganography) {
protected ImageSteganography doInBackground(ImageSteganography... imageSteganographies) {

//making result object
result = new ImageSteganography();;
result = new ImageSteganography();

//If it is not already decoded
if (imageSteganographies.length > 0){
Expand Down Expand Up @@ -113,24 +113,10 @@ protected ImageSteganography doInBackground(ImageSteganography... imageSteganogr
//secret key provided is right
result.setSecretKeyWrong(false);

//decompressing the decrypted_message
try {
decompressed_message = Zipping.decompress(decrypted_message.getBytes("ISO-8859-1"));
Log.d(TAG, "Original Message : " + decompressed_message);
} catch (Exception e) {
e.printStackTrace();
}

if (!Utility.isStringEmpty(decompressed_message)) {
try {
//Setting message to result
if (result != null && result.isDecoded())
result.setMessage(decompressed_message);

} catch (Exception e) {
e.printStackTrace();
}
}
// Set Results

result.setMessage(decrypted_message);


//free memory
for (Bitmap bitm : srcEncodedList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ protected ImageSteganography doInBackground(ImageSteganography... imageSteganogr
List<Bitmap> src_list = Utility.splitImage(bitmap);

//encoding encrypted compressed message into image

List<Bitmap> encoded_list = EncodeDecode.encodeMessage(src_list, textStegnography.getEncrypted_message(), new EncodeDecode.ProgressHandler() {

//Progress Handler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ayush.imagesteganographylibrary.Utils;

import android.util.Log;

import java.nio.charset.Charset;

import javax.crypto.Cipher;
Expand All @@ -26,9 +28,13 @@ public static String encryptMessage(String message, String secret_key) throws Ex

byte[] encrypted;

encrypted = cipher.doFinal(message.getBytes());
encrypted = cipher.doFinal(message.getBytes());

Log.d("crypto", "Encrypted in crypto (mine): " + encrypted + "string: " +android.util.Base64.encodeToString(cipher.doFinal(message.getBytes()),0) );

Log.d("crypto", "Encrypted in crypto (theirs): " + cipher.doFinal(message.getBytes())+ "string : " + new String(encrypted));

return new String(encrypted, "ISO-8859-1");
return android.util.Base64.encodeToString(cipher.doFinal(message.getBytes()),0);
}

//Decryption Method
Expand All @@ -38,6 +44,7 @@ public static String encryptMessage(String message, String secret_key) throws Ex
*/
public static String decryptMessage(String encrypted_message, String secret_key) throws Exception {

Log.d("Decrypt", "message: + " + encrypted_message);
// Creating key and cipher
SecretKeySpec aesKey = new SecretKeySpec(secret_key.getBytes(), "AES");
Cipher cipher;
Expand All @@ -47,10 +54,10 @@ public static String decryptMessage(String encrypted_message, String secret_key)

// decrypting the text
cipher.init(Cipher.DECRYPT_MODE, aesKey);

String decrypted;

decrypted = new String(cipher.doFinal(encrypted_message.getBytes(Charset.forName("ISO-8859-1"))));
byte[] decoded;
decoded = android.util.Base64.decode(encrypted_message.getBytes(),0);
decrypted = new String(cipher.doFinal(decoded));

//returning decrypted text
return decrypted;
Expand Down

0 comments on commit 64bdbbc

Please sign in to comment.