Added fingerprint

This commit is contained in:
Marcin Wozniak 2019-11-21 18:16:54 +01:00
parent d506c71afa
commit 7412849f5a
4 changed files with 64 additions and 34 deletions

View File

@ -26,7 +26,7 @@ public class FirstPassword extends Activity {
{ {
MessageDigest digest; MessageDigest digest;
String generatedPassword = null; String generatedPassword = null;
String salt = "cnsakn"; String salt = "Z7F4nGZEYa2AZQ3TVTrgYXJkezWPzDuGh54zVrjWtkGQLQNPFN5edJWvzh5rVgXbY5fv489JHourDWHMTKEumk24e6MzmwC8rCTPCHgKvWCnCjPG4HN3mLuWjWG3yabF";
try try
{ {
MessageDigest md = MessageDigest.getInstance("SHA-512"); MessageDigest md = MessageDigest.getInstance("SHA-512");

View File

@ -25,7 +25,7 @@ import java.security.NoSuchAlgorithmException;
public class FormPassword extends Activity { public class FormPassword extends Activity {
private static final String FILE_NAME = "passwd.txt"; private static final String FILE_NAME = "passwd.txt";
private static String input; private static String input;
private static String newpass;
public String readFile(String filename) throws IOException { public String readFile(String filename) throws IOException {
String content = null; String content = null;
@ -51,7 +51,7 @@ public class FormPassword extends Activity {
{ {
MessageDigest digest; MessageDigest digest;
String generatedPassword = null; String generatedPassword = null;
String salt = "cnsakn"; String salt = "Z7F4nGZEYa2AZQ3TVTrgYXJkezWPzDuGh54zVrjWtkGQLQNPFN5edJWvzh5rVgXbY5fv489JHourDWHMTKEumk24e6MzmwC8rCTPCHgKvWCnCjPG4HN3mLuWjWG3yabF";
try try
{ {
MessageDigest md = MessageDigest.getInstance("SHA-512"); MessageDigest md = MessageDigest.getInstance("SHA-512");
@ -76,7 +76,7 @@ public class FormPassword extends Activity {
private String unSHA512(String passwordToHash) private String unSHA512(String passwordToHash)
{ {
String generatedPassword = null; String generatedPassword = null;
String salt = "cnsakn"; String salt = "Z7F4nGZEYa2AZQ3TVTrgYXJkezWPzDuGh54zVrjWtkGQLQNPFN5edJWvzh5rVgXbY5fv489JHourDWHMTKEumk24e6MzmwC8rCTPCHgKvWCnCjPG4HN3mLuWjWG3yabF";
try try
{ {
MessageDigest md = MessageDigest.getInstance("SHA-512"); MessageDigest md = MessageDigest.getInstance("SHA-512");
@ -113,12 +113,16 @@ public class FormPassword extends Activity {
renewpassword = (EditText) findViewById(R.id.renewpassword); renewpassword = (EditText) findViewById(R.id.renewpassword);
confirm = (Button) findViewById(R.id.button); confirm = (Button) findViewById(R.id.button);
confirm.setOnClickListener(new View.OnClickListener() { confirm.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) { public void onClick(View arg0) {
final String filename = getFilesDir() + "/passwd.txt"; final String filename = getFilesDir() + "/passwd.txt";
File file = new File(filename); File file = new File(filename);
input = currentpassword.getText().toString(); input = currentpassword.getText().toString();
newpass = newpassword.getText().toString();
String SHAinput = unSHA512(input); String SHAinput = unSHA512(input);
currentpassword.setText(""); currentpassword.setText("");
String password = null; String password = null;
@ -136,6 +140,10 @@ public class FormPassword extends Activity {
Toast.LENGTH_SHORT); Toast.LENGTH_SHORT);
toast.show(); toast.show();
Intent myIntent3 = new Intent(FormPassword.this,
Noto.class);
startActivity(myIntent3);
try { try {
fos = openFileOutput(FILE_NAME, MODE_PRIVATE); fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
fos.write(text.getBytes()); fos.write(text.getBytes());
@ -176,4 +184,10 @@ public class FormPassword extends Activity {
} }
}); });
} }
public static String getInput() {
return input;
}
public static String getInputNew() {
return newpass;
}
} }

View File

@ -61,7 +61,7 @@ public class MainActivity extends AppCompatActivity {
private String unSHA512(String passwordToHash) private String unSHA512(String passwordToHash)
{ {
String generatedPassword = null; String generatedPassword = null;
String salt = "cnsakn"; String salt = "Z7F4nGZEYa2AZQ3TVTrgYXJkezWPzDuGh54zVrjWtkGQLQNPFN5edJWvzh5rVgXbY5fv489JHourDWHMTKEumk24e6MzmwC8rCTPCHgKvWCnCjPG4HN3mLuWjWG3yabF";
try try
{ {
MessageDigest md = MessageDigest.getInstance("SHA-512"); MessageDigest md = MessageDigest.getInstance("SHA-512");
@ -167,6 +167,7 @@ public class MainActivity extends AppCompatActivity {
}); });
} }
public static String getInput() { public static String getInput() {
return input; return input;
} }
@ -175,7 +176,7 @@ public class MainActivity extends AppCompatActivity {
private void showBiometricPrompt() { private void showBiometricPrompt() {
BiometricPrompt.PromptInfo promptInfo = BiometricPrompt.PromptInfo promptInfo =
new BiometricPrompt.PromptInfo.Builder() new BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app") .setTitle("Biometric login for Encrypted Noto")
.setSubtitle("Log in using your biometric credential") .setSubtitle("Log in using your biometric credential")
.setNegativeButtonText("Cancel") .setNegativeButtonText("Cancel")
.build(); .build();

View File

@ -6,25 +6,22 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException; import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
@ -32,15 +29,31 @@ public class Noto extends AppCompatActivity {
EditText ChangeNote; EditText ChangeNote;
Button SaveNote; Button SaveNote;
private static final String FILE_NAME = "notes.txt"; private static final String FILE_NAME = "notes.txt";
private static String keyStreach;
static String text;
private EditText textInputNotes;
private static String keyMultiply;
private static String key; private static String key;
private static String initVector; private static String initVector;
protected static String password; protected static String password;
protected static String soil= "yWaDPPsFMXxXwEJsTcf42";
int pom=0; public String keyStreaching(String pass) throws NoSuchAlgorithmException {
String salt = "NkAeUcRvdBwnrLVC4kbSwzTCeLBzZjxA2puRCvq47i5Le3Qanmxv2C2Q3REn77YHGpCqt8yjgFiiyV8HHRPSaLzzZBC8WHVwas8RTiau79wKnk5Q4zkp2EVq5jNwh3bd";
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] byteData;
StringBuilder sb = new StringBuilder(64);
for (int a = 0; a < 100000; a++) {
md.update((pass + salt).getBytes());
byteData = md.digest();
for (int i = 0; i < byteData.length; i++) {
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
}
key = sb.toString();
sb.delete(0, sb.length());
}
return key;
}
@Override @Override
@ -51,7 +64,7 @@ public class Noto extends AppCompatActivity {
ChangeNote = (EditText) findViewById(R.id.changeNote); ChangeNote = (EditText) findViewById(R.id.changeNote);
SaveNote = (Button) findViewById(R.id.SaveNote); SaveNote = (Button) findViewById(R.id.SaveNote);
FileInputStream fis = null; FileInputStream fis = null;
password = MainActivity.getInput(); password = ((password = MainActivity.getInput()) != null) ? password : FormPassword.getInput();
try { try {
FileInputStream fileInputStream = null; FileInputStream fileInputStream = null;
@ -62,9 +75,9 @@ public class Noto extends AppCompatActivity {
ChangeNote.setText(ciphertext.toString()); ChangeNote.setText(ciphertext.toString());
keyMultiply = password + soil + password + soil + soil + password + soil; keyStreach = keyStreaching(password);
key = keyMultiply.substring(4, 20); key = keyStreach.substring(4, 20);
initVector = keyMultiply.substring(7, 23); initVector = keyStreach.substring(7, 23);
byte[] bytesKey = key.getBytes("UTF-8"); byte[] bytesKey = key.getBytes("UTF-8");
byte[] bytesIV = initVector.getBytes("UTF-8"); byte[] bytesIV = initVector.getBytes("UTF-8");
@ -100,24 +113,26 @@ public class Noto extends AppCompatActivity {
public void save (View v) throws IOException { public void save (View v) throws IOException {
try { try {
String text = ChangeNote.getText().toString();
FileOutputStream fos = null;
keyMultiply = password + soil + password + soil + soil + password + soil; String text = ChangeNote.getText().toString();
key = keyMultiply.substring(4, 20); FileOutputStream fos = null;
initVector = keyMultiply.substring(7, 23); password = ((password = FormPassword.getInputNew()) != null) ? password : MainActivity.getInput();
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); keyStreach = keyStreaching(password);
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); key = keyStreach.substring(4, 20);
initVector = keyStreach.substring(7, 23);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
byte[] encrypted = cipher.doFinal(text.getBytes()); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
fos = openFileOutput(FILE_NAME, MODE_PRIVATE); byte[] encrypted = cipher.doFinal(text.getBytes());
fos.write(encrypted);
Toast.makeText(this, "Saved to " + getFilesDir() + "/" + FILE_NAME, Toast.LENGTH_LONG).show(); fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
fos.write(encrypted);
Toast.makeText(this, "Saved to " + getFilesDir() + "/" + FILE_NAME, Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();