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;
String generatedPassword = null;
String salt = "cnsakn";
String salt = "Z7F4nGZEYa2AZQ3TVTrgYXJkezWPzDuGh54zVrjWtkGQLQNPFN5edJWvzh5rVgXbY5fv489JHourDWHMTKEumk24e6MzmwC8rCTPCHgKvWCnCjPG4HN3mLuWjWG3yabF";
try
{
MessageDigest md = MessageDigest.getInstance("SHA-512");

View File

@ -25,7 +25,7 @@ import java.security.NoSuchAlgorithmException;
public class FormPassword extends Activity {
private static final String FILE_NAME = "passwd.txt";
private static String input;
private static String newpass;
public String readFile(String filename) throws IOException {
String content = null;
@ -51,7 +51,7 @@ public class FormPassword extends Activity {
{
MessageDigest digest;
String generatedPassword = null;
String salt = "cnsakn";
String salt = "Z7F4nGZEYa2AZQ3TVTrgYXJkezWPzDuGh54zVrjWtkGQLQNPFN5edJWvzh5rVgXbY5fv489JHourDWHMTKEumk24e6MzmwC8rCTPCHgKvWCnCjPG4HN3mLuWjWG3yabF";
try
{
MessageDigest md = MessageDigest.getInstance("SHA-512");
@ -76,7 +76,7 @@ public class FormPassword extends Activity {
private String unSHA512(String passwordToHash)
{
String generatedPassword = null;
String salt = "cnsakn";
String salt = "Z7F4nGZEYa2AZQ3TVTrgYXJkezWPzDuGh54zVrjWtkGQLQNPFN5edJWvzh5rVgXbY5fv489JHourDWHMTKEumk24e6MzmwC8rCTPCHgKvWCnCjPG4HN3mLuWjWG3yabF";
try
{
MessageDigest md = MessageDigest.getInstance("SHA-512");
@ -113,12 +113,16 @@ public class FormPassword extends Activity {
renewpassword = (EditText) findViewById(R.id.renewpassword);
confirm = (Button) findViewById(R.id.button);
confirm.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
final String filename = getFilesDir() + "/passwd.txt";
File file = new File(filename);
input = currentpassword.getText().toString();
newpass = newpassword.getText().toString();
String SHAinput = unSHA512(input);
currentpassword.setText("");
String password = null;
@ -136,6 +140,10 @@ public class FormPassword extends Activity {
Toast.LENGTH_SHORT);
toast.show();
Intent myIntent3 = new Intent(FormPassword.this,
Noto.class);
startActivity(myIntent3);
try {
fos = openFileOutput(FILE_NAME, MODE_PRIVATE);
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)
{
String generatedPassword = null;
String salt = "cnsakn";
String salt = "Z7F4nGZEYa2AZQ3TVTrgYXJkezWPzDuGh54zVrjWtkGQLQNPFN5edJWvzh5rVgXbY5fv489JHourDWHMTKEumk24e6MzmwC8rCTPCHgKvWCnCjPG4HN3mLuWjWG3yabF";
try
{
MessageDigest md = MessageDigest.getInstance("SHA-512");
@ -167,6 +167,7 @@ public class MainActivity extends AppCompatActivity {
});
}
public static String getInput() {
return input;
}
@ -175,7 +176,7 @@ public class MainActivity extends AppCompatActivity {
private void showBiometricPrompt() {
BiometricPrompt.PromptInfo promptInfo =
new BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app")
.setTitle("Biometric login for Encrypted Noto")
.setSubtitle("Log in using your biometric credential")
.setNegativeButtonText("Cancel")
.build();

View File

@ -6,25 +6,22 @@ import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
@ -32,15 +29,31 @@ public class Noto extends AppCompatActivity {
EditText ChangeNote;
Button SaveNote;
private static final String FILE_NAME = "notes.txt";
static String text;
private EditText textInputNotes;
private static String keyMultiply;
private static String keyStreach;
private static String key;
private static String initVector;
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
@ -51,7 +64,7 @@ public class Noto extends AppCompatActivity {
ChangeNote = (EditText) findViewById(R.id.changeNote);
SaveNote = (Button) findViewById(R.id.SaveNote);
FileInputStream fis = null;
password = MainActivity.getInput();
password = ((password = MainActivity.getInput()) != null) ? password : FormPassword.getInput();
try {
FileInputStream fileInputStream = null;
@ -62,9 +75,9 @@ public class Noto extends AppCompatActivity {
ChangeNote.setText(ciphertext.toString());
keyMultiply = password + soil + password + soil + soil + password + soil;
key = keyMultiply.substring(4, 20);
initVector = keyMultiply.substring(7, 23);
keyStreach = keyStreaching(password);
key = keyStreach.substring(4, 20);
initVector = keyStreach.substring(7, 23);
byte[] bytesKey = key.getBytes("UTF-8");
byte[] bytesIV = initVector.getBytes("UTF-8");
@ -100,12 +113,14 @@ public class Noto extends AppCompatActivity {
public void save (View v) throws IOException {
try {
String text = ChangeNote.getText().toString();
FileOutputStream fos = null;
password = ((password = FormPassword.getInputNew()) != null) ? password : MainActivity.getInput();
keyStreach = keyStreaching(password);
key = keyStreach.substring(4, 20);
initVector = keyStreach.substring(7, 23);
keyMultiply = password + soil + password + soil + soil + password + soil;
key = keyMultiply.substring(4, 20);
initVector = keyMultiply.substring(7, 23);
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");