An app for encrypting text in Sketchware

Create a new app with four pages or Activity: MainActivity, NewnoteActivity, OldnoteActivity, ViewnoteActivity.

In main.xml add two buttons. On button_new click, move to NewnoteActivity. On button_old click, move to OldnoteActivity.

In newnote.xml View, add an Edittext (edittext1) and a Button (fab1).

In NewnoteActivity, add a Shared preferences component (sp:sp).

Add a more block called newitems and put following code in it:


Add another more block called encrypt and put following code in it:



Add two string variables: 'key' and 'filePath'. Add another more block called saveByteArrayToFile(filePath) as shown in image below:


Here, it shows a dialog box. When save button is clicked,
Convert the secret key bye array to String called 'key' using following code:



Then save the string 'key' to SharedPreferences using file name as key.

Then save the encrypted text to the 'filePath' using following code:



On save (fab) button click event,
Use following code to encrypt text in edittext1. The encrypted text is cipherText.



Define the String filePath. Set it to a file in package data directory as shown in image.

Now use more block saveByteArrayToFile(filePath) to save the encrypted byte array. The use code to catch exceptions.


In OldnoteActivity, add a ListView. Create a custom view for ListView items. In the custom view, add a TextView and a delete button. Add a String list (fileslist) and a MapList (maplist). Also add a number variables (n).
In onCreate, get list of all files in package data directory to fileslist. From fileslist, add all items to maplist using key filename, and display in ListView, using blocks shown in image below.


In ListView onBindCustomView,  display filename in textview1. On delete button click, delete the file and the filePath from string list and map list.

In ListView onItemClick event, use intent to move to ViewnoteActivity, saving file path as extra key.


In ViewnoteActivity, add a TextView (textview1) and a Button for decrypting. Then add a SharedPreferences component (sp:sp) and two String variables 'mykey' and 'filePath'.

Add a more block called newitems and put following code in it:


Add another more block called decrypt and put following code in it:



In onCreate,
Set String filePath to (Activity get extra key filepath).


Use following code to get data from file to byte array cipherText, and display cipherText in textview1.


Set String mykey to data from SharedPreferences.
Then use following code, to convert String 'mykey' to byte array 'secretKeyen'.



On decrypt button click, use following code to decrypt cipherText and display in textview1.


That's all.
Watch the video below.

Comments

Popular posts from this blog

Simple car racing android game in Sketchware

Creating a Drawing View in Sketchware

Enable Fullscreen for Youtube videos in WebView

How to enable upload from webview in Sketchware?

List of Calendar Format symbols valid in Sketchware