Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnurahar committed Dec 20, 2020
1 parent 03293ae commit 4249f5f
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 323 deletions.
116 changes: 0 additions & 116 deletions app/.idea/codeStyles/Project.xml

This file was deleted.

21 changes: 0 additions & 21 deletions app/.idea/gradle.xml

This file was deleted.

25 changes: 0 additions & 25 deletions app/.idea/jarRepositories.xml

This file was deleted.

14 changes: 0 additions & 14 deletions app/.idea/misc.xml

This file was deleted.

12 changes: 0 additions & 12 deletions app/.idea/runConfigurations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions app/.idea/vcs.xml

This file was deleted.

1 change: 1 addition & 0 deletions app/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>

<application
android:allowBackup="false"
Expand Down
84 changes: 0 additions & 84 deletions app/app/src/main/java/com/example/project1/ProfileFragment.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,19 @@
package com.example.project1;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.InputType;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;

import java.security.KeyStore;
import java.security.MessageDigest;
import java.util.Objects;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import okhttp3.internal.Util;

public class ProfileFragment extends Fragment {

TextView profile_phone, profilePublicKey;
Button viewBalancebtn;
private static final String AES_MODE = "AES/ECB/PKCS5Padding";
String smsString = null, encryptText = null, actualText =null;
KeyStore keyStore = null;
EnCryptor encryptor;
String passforSMSEncruption ;

private Context mContext;

@Override
Expand All @@ -60,7 +35,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

profile_phone = view.findViewById(R.id.profile_phone);
profilePublicKey = view.findViewById(R.id.text_view_public_key);
viewBalancebtn = view.findViewById(R.id.view_balance_btn);

if(mContext != null) {
String p = Utils.getStringFromUserData(mContext, "phone");
Expand All @@ -69,65 +43,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
profilePublicKey.setText(pk);
}

UserLogin userLogin = new UserLogin();
passforSMSEncruption = userLogin.smsEncryptionPass;

viewBalancebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
encryptText = "retrievebalance";
try {
smsString = encrypt(encryptText, passforSMSEncruption);
passforSMSEncruption = null;
} catch (Exception e) {
e.printStackTrace();
}
sendSMS();
}
});

return view;
}

private void sendSMS() {
Uri uri = Uri.parse("smsto:+12517650405");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", smsString);
startActivity(intent);

try {
startActivity(intent);
} catch (ActivityNotFoundException ex) {
Toast.makeText(mContext, ex.getMessage(), Toast.LENGTH_SHORT).show();
}
}

private String encrypt(String data, String password) throws Exception {
SecretKeySpec key = generateKey(password);

Cipher cipher = Cipher.getInstance(AES_MODE);
cipher.init(Cipher.ENCRYPT_MODE, key);

byte[] encodedBytes = cipher.doFinal(data.getBytes());
String encryptedBase64Encoded = Base64.encodeToString(encodedBytes, Base64.DEFAULT);
return encryptedBase64Encoded;
}

private SecretKeySpec generateKey(String password) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
SecretKeySpec key = new SecretKeySpec(password.getBytes(), "AES");
return key;
}

private String decrypt(String encryptedText, String password) throws Exception{
SecretKeySpec key = generateKey(password);
Log.i("check5", String.valueOf(key));
byte[] decodedVal = Base64.decode(encryptedText, Base64.DEFAULT);
Cipher cipher = Cipher.getInstance(AES_MODE);
cipher.init(Cipher.DECRYPT_MODE,key);
String decryptedValText = new String(cipher.doFinal(decodedVal));
Log.i("check7", decryptedValText);
return decryptedValText;
}

}
9 changes: 1 addition & 8 deletions app/app/src/main/java/com/example/project1/SendFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,14 @@

public class SendFragment extends Fragment {

// private String passwordFroSMSencryption = "1234567890ABCDEF";
// private String privateKey = "97d8cb40d55f97fa4a9dcbb9d89b159128b95043edfd835467553f3b5c69d7af";

private static final String AES_MODE = "AES/ECB/PKCS5Padding";

EditText etSenderPublicKey, etAmount;
Context context;
Button sendBtn;
String smsString = null, encryptText = null, actualText =null;
KeyStore keyStore = null;

EnCryptor encryptor;

String passforSMSEncruption ;

@Nullable
Expand All @@ -81,7 +76,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onClick(View v) {
encryptText = etSenderPublicKey.getText().toString().trim() + ":" + etAmount.getText().toString().trim();
try {
smsString = encrypt(encryptText, passforSMSEncruption);
smsString = encrypt(encryptText, passforSMSEncruption).trim();
passforSMSEncruption = null;
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -125,12 +120,10 @@ private SecretKeySpec generateKey(String password) throws Exception {

private String decrypt(String encryptedText, String password) throws Exception{
SecretKeySpec key = generateKey(password);
Log.i("check5", String.valueOf(key));
byte[] decodedVal = Base64.decode(encryptedText, Base64.DEFAULT);
Cipher cipher = Cipher.getInstance(AES_MODE);
cipher.init(Cipher.DECRYPT_MODE,key);
String decryptedValText = new String(cipher.doFinal(decodedVal));
Log.i("check7", decryptedValText);
return decryptedValText;
}

Expand Down
Loading

0 comments on commit 4249f5f

Please sign in to comment.