Posts

Android Open Source

Image
 Android RSA Library Let's make a library for working with RSA encryption. It's comfortable.   There are many examples for working with RSA in Android. But this example works in a real application.  Android RSA Library  

Andtoid Open Source

  RSA Android Java To encrypt text using RSA, you need to write quite a lot of code. It is not comfortable. I tried to make a separate class for working with RSA. It turned out like this. But this is the first option. We will improve it. //===================================================== // // This example shows how easy it is to generate RSA key pairs, // encrypt text, write text, read text from a file, decode text, // store encryption keys, and recover encryption keys. If you have // a special class RSACode.java // //===================================================== public class MainActivity extends AppCompatActivity {     //=====================================================     //     // RSA and Write encoded text to file and Read from file oflameron.txt     // rsaload.Load(FILENAME, str2)     //     //=====================================================     final static String LOG_TAG = "myLogs";     public static String str=" "; //File contents

Android Open Source

  Android Open Java Project When encrypting information, cryptographic providers are widely used - an independent module that allows you to perform cryptographic operations in operating systems. With a high degree of probability, the one who created the cryptographic provider has more opportunities to decode encrypted information. Android has its own crypto providers, accessed through the mechanism  Crypto API If you encrypt information about the number of bottles of sparkling water sold in your store, then this is more than enough. If you're writing encryption software for a business with hundreds of thousands of dollars in revenue, you might consider making the information unrecoverable. Well, here is the answer. It is necessary to make the encrypted information corrupted. And if you messed it up yourself, then you know how to fix it "on the other side". And here you should not use transformations by functions. To spoil - so to spoil!   Android Open Java Project    

Android Open Source

  Open Source Java App RSA Crypto In the previous post, there was a joke about the fact that encryption keys in PCA cannot be written to a file, sent, or converted. For those whose nerves are well tuned, let's continue. Encryption keys can be saved to a file and restored from a file. Although this is not the most secure way to store them. byte [] pubKeyBytes = new byte[pubKeyLength]; FileInputStream privIn = new FileInputStream (privateKey); FileInputStream pubIn = new FileInputStream (publicKey); privIn. read (privKeyBytes); pubIn. read (pubKeyBytes); pubIn. close (); KeyFactory keyFactory = KeyFactory. getInstance ( "RSA" ); EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec (privKeyBytes); EncodedKeySpec publicKeySpec = new X509EncodedKeySpec (pubKeyBytes); crypto.keyPair = new KeyPair(keyFactory. generatePublic (publicKeySpec), keyFactory. generatePrivate (privateKeySpec)); crypto.base64 = base64;   That's enough to get it all done. Of course, t

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 {     //================