Posts

Showing posts with the label Encrypt and decrypt in Sketchware

Encrypt and decrypt text

Image
Here is a simple example of encryption and decryption in Sketchware. Follow the steps below. 1. Create a new project in Sketchware. 2. In  main.xml  add a LinearV  linear1  inside a ScrollV vscroll1 . Inside this add an EditText edittext1 , add two Buttons button1 and button2, and two TextViews textview1 and textview2 . 3. Create a More Block  extra , here use an add source directly block and put following codes. } javax.crypto.KeyGenerator keyGenerator; javax.crypto.SecretKey secretKey; byte[] secretKeyen; String strSecretKey; byte[] IV = new byte[16]; byte[] cipherText; public static byte[] encrypt(byte[] plaintext, javax.crypto.SecretKey key, byte[] IV) throws Exception { javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance("AES"); javax.crypto.spec.SecretKeySpec keySpec = new javax.crypto.spec.SecretKeySpec(key.getEncoded(), "AES"); javax.crypto.spec.IvParameterSpec ivSpec = new javax.crypto.spec.IvParameterSpec(IV); cipher....