Skip to content

Commit

Permalink
Clean up class name & minor wibbles.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Potoczny-Jones committed Nov 29, 2014
1 parent c8fa822 commit f276bcb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
5 changes: 2 additions & 3 deletions AesCbcPadding.java → AesCbcWithIntegrity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Created by Isaac Potoczny-Jones on 11/12/14.
*/

package com.tozny.crypto.basicaescbc;
package com.tozny.crypto.android;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
Expand Down Expand Up @@ -58,15 +58,14 @@
import android.util.Base64;
import android.util.Log;

import static java.util.Arrays.copyOf;
import static java.util.Arrays.copyOfRange;

/**
* Simple library for the "right" defaults for AES key generation, encryption,
* and decryption using 128-bit AES, CBC, PKCS5 padding, and a random 16-byte IV
* with SHA1PRNG. Integrity with HmacSHA256.
*/
public class AesCbcPadding {
public class AesCbcWithIntegrity {
private static final String CIPHER_TRANSFORMATION = "AES/CBC/PKCS5Padding";
private static final String CIPHER = "AES";
private static final String RANDOM_ALGORITHM = "SHA1PRNG";
Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions MyActivity.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tozny.crypto.basicaescbc;
package com.tozny.crypto.android;

import android.app.Activity;
import android.os.Bundle;
Expand All @@ -9,14 +9,14 @@
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;

import static com.tozny.crypto.basicaescbc.AesCbcPadding.generateKeyFromPassword;
import static com.tozny.crypto.basicaescbc.AesCbcPadding.generateSalt;
import static com.tozny.crypto.basicaescbc.AesCbcPadding.keyString;
import static com.tozny.crypto.basicaescbc.AesCbcPadding.decryptString;
import static com.tozny.crypto.basicaescbc.AesCbcPadding.encrypt;
import static com.tozny.crypto.basicaescbc.AesCbcPadding.generateKey;
import static com.tozny.crypto.basicaescbc.AesCbcPadding.keys;
import static com.tozny.crypto.basicaescbc.AesCbcPadding.saltString;
import static com.tozny.crypto.android.AesCbcWithIntegrity.generateKeyFromPassword;
import static com.tozny.crypto.android.AesCbcWithIntegrity.generateSalt;
import static com.tozny.crypto.android.AesCbcWithIntegrity.keyString;
import static com.tozny.crypto.android.AesCbcWithIntegrity.decryptString;
import static com.tozny.crypto.android.AesCbcWithIntegrity.encrypt;
import static com.tozny.crypto.android.AesCbcWithIntegrity.generateKey;
import static com.tozny.crypto.android.AesCbcWithIntegrity.keys;
import static com.tozny.crypto.android.AesCbcWithIntegrity.saltString;


public class MyActivity extends Activity {
Expand All @@ -29,7 +29,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_my);

try {
AesCbcPadding.SecretKeys key;
AesCbcWithIntegrity.SecretKeys key;
if (PASSWORD_BASED_KEY) {//example for password based keys
String salt = saltString(generateSalt());
//If you generated the key from a password, you can store the salt and not the key.
Expand All @@ -53,7 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {

// Read from storage & decrypt
key = keys(keyStr); // alternately, regenerate the key from password/salt.
AesCbcPadding.CipherTextIvMac civ = encrypt(textToEncrypt, key);
AesCbcWithIntegrity.CipherTextIvMac civ = encrypt(textToEncrypt, key);
Log.i("Tozny", "Encrypted: " + civ.toString());

String decryptedText = decryptString(civ, key);
Expand Down

0 comments on commit f276bcb

Please sign in to comment.