Posts

Showing posts from August, 2022

Android Open Source

  Open Source Java App RSA Crypto In order to be able to decrypt the encoded text, we need to save and use the private key. The private key can be converted to a string variable and saved to a file. The file can then be read into a string variable. But it will not be possible to recover the private key. No option to convert any data to RSA key format   As they say, this is done for safety. So that you do not store the private key in files in an insecure area. This statement can be disputed, but for practical application this dispute does not make sense. To save and reuse the private key in your application, you need to use STORAGE. Android REPOSITORY. It's the same as Windows. It uses the utility  MCC Android KeyStore API Generate a key and save it in the KeyStore           final KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore"); final KeyGenParameterSpec keyGenParameterSpec = new KeyGenParameterSpec.Builder(&qu

Android Open Source

Image
  Android Java Project RSA Crypto In the previous post, we created a project in which the text from a variable is encrypted using a 1024 bit RSA algorithm. Save the encrypted text to a file oflameron.txt Let's check if the application will work correctly if we just read the ciphertext from the file Let's comment out the module for encrypting and writing text to a file oflameron.txt Run the application from Android Studio on the same smartphone   It can be seen that there is no error in the decoding algorithm, but instead of the original text - "garbage information" Why and what to do - in the next post   Android Java Project  

Android Open Source

  Open Source RSA Crypto Android RSA Crypto Here we have added to the project writing ciphertext to a file oflameron.txt and reading from a ciphertext file. Layout file - in the previous post MainActivity.java  package org.o7planning.bincharbin; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; import android.os.Build; import android.os.Bundle; import android.util.Base64; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.security.Key; import java.security.KeyPair; import java.security.KeyPairGenerator; import javax.crypto.Cipher; public class MainActivity extends AppCompatActivity {     //================

Android Open Source

  Open Source Java App RSA Crypto We have redesigned the project to demonstrate RSA encryption . Layout file remains the same activity_main.xml   <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".MainActivity">     <TableLayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:stretchColumns="*"         app:layout_constraintBottom_toBottomOf="parent"         android:id="@+id/tableLayout1">         <TableRow             android:id="@+id/tableRow1"             android:layou

Android Open Source

  Open Source Java App RSA Crypto The project with PCA encryption works fine. Key generation is performed and the given text is encrypted and decoded. But in practice, the ciphertext must be stored, read and decoded. Let's make this version of the project. Then, when our project is running, we will add it to the CryptoNOTE  project. At the same time, the previous encryption option - the symmetric AEC algorithm is also useful to us. First, let's save the ciphertext to a file and read the text from the file. Then we will try to decode it. Source CryptoNOTE project (No RSA)    CryptoNOTE_AES.ZIP  https://drive.google.com/file/d/1QhW9SRS6-fWGyV6hAAifxlUFe8PngCn9/view?usp=sharing  P.S. An interesting option for applying PCA encryption - in combination with databases (for example, goods, users, documents) Open Source Java App  

Android Open Source

RSA crypto example Because the RSA algorithm has a higher resistance against decoding, then using it in your personal notepad for a smartphone has advantages. Let's take a ready-made Open Source Java project CryptoNOTE and replace AES encryption with RSA encryption. Source Code - CryptoNOTE_AES.ZIP  https://drive.google.com/file/d/1QhW9SRS6-fWGyV6hAAifxlUFe8PngCn9/view?usp=sharing   Full Java Project   RSA crypto example

Android Open Source

  RSA Java Crypto Project MainActivity.java Full working example. The markup is given in the previous post. package org.o7planning.rsa; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.Base64; import android.util.Log; import android.view.View; import android.widget.TextView; import java.security.Key; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.Provider; import java.security.Security; import java.util.Iterator; import java.util.TreeSet; import javax.crypto.Cipher; public class MainActivity extends AppCompatActivity {     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         // Original text         String testText = "Open Source Java Project";         TextView originalTextView = (TextView) findViewById(R.id.TXTV);         originalTextView.setText("[ORIGINAL]:\n" +

RSA crypto example

 Android RSA Open Source The RSA encryption algorithm provides higher resistance against decoding than AES Full working example in Java activity_main.xml  <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".MainActivity">     <TableLayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:stretchColumns="*"         app:layout_constraintBottom_toBottomOf="parent"         android:id="@+id/tableLayout1">         <TableRow             android:id="@+id/tableRow1"             andro

Android RSA Crypto Code

 RSA Example We use the following Java code to encode text " Open Source Java Projects OFLAMERON " using the RSA algorithm and its subsequent decoding    // Original text     String testText = " Open Source Java Projects OFLAMERON ";     TextView originalTextView = (TextView) findViewById(R.id.textViewOriginal);     originalTextView.setText("[ORIGINAL]:\n" + testText + "\n");     // Generate key pair for 1024-bit RSA encryption and decryption     Key publicKey = null;     Key privateKey = null;     try {         KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");         kpg.initialize(1024); //1024 Key         KeyPair kp = kpg.genKeyPair();         publicKey = kp.getPublic(); //Public Key         privateKey = kp.getPrivate(); //Private Key     } catch (Exception e) {         Log.e("Crypto", "RSA key pair error");     }     // Encode the original data with RSA private key     byte[] encodedBytes = null;    

Android Crypto Project

  Open Source Java Project The RSA algorithm provides significantly stronger encryption than AES It uses asymmetric encryption as opposed to AES. Writing Java code for RSA encryption is much more difficult if you do not use Android's internal algorithms.   We use it. Let's take the previous Open Source Project project as a basis   Source Code - CryptoNOTE_AES.ZIP  https://drive.google.com/file/d/1QhW9SRS6-fWGyV6hAAifxlUFe8PngCn9/view?usp=sharing   Full Java Project Open Source Java Project  

CryptoNOTE AES

 Open Source Java Projext Android Studio Now we will show how to encrypt text in AES. Highlighted comment - the simplest encryption option with which the application was debugged In Main Activity     //==========================================================     //   Text oflameron.txt CODING     //==========================================================     public void Code() {         char ec = 0; //One character from the read text         String KTxt = ""; //Encoded text         elenght = str.length(); //Amount of data from EditText to encode         // The number of characters in the oflameron.txt file - in the elenght variable         // Encoding text from str variable         // Encoding is simple - increase the character code by 1         ////for (int symbol = 0; symbol < elenght; symbol++) {         ////    ec = str.charAt(symbol); //Select one character at a time         ////    int code = (int) ec; //Get the character code in the variable "c"     

CryptoNOTE Open Source Project

  AES encryption Class This is class AESHelper in project CryptoNOTE     private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {         SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");         Cipher cipher = Cipher.getInstance("AES");         cipher.init(Cipher.ENCRYPT_MODE, skeySpec);         byte[] encrypted = cipher.doFinal(clear);         return encrypted;     }   Encryption and decryption      private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {         SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");         Cipher cipher = Cipher.getInstance("AES");         cipher.init(Cipher.DECRYPT_MODE, skeySpec);         byte[] decrypted = cipher.doFinal(encrypted);         return decrypted;     } String conversion      public static String toHex(String txt) {         return toHex(txt.getBytes());     }     public static String fromHex(String hex) {         return new String(toByte(hex));