Encrypt/Decrypt Data with SimpleCrypto JS
INTRO
A quick demo to show how to use the SimpleCrypto javascript to encrypt and decrypt data locally in your app. You require two html files, one to encrypt and one to decrypt and the SimpleCrypto js file.
HTML
encrypt.html
<!DOCTYPE html>
<html>
<meta name=“viewport” content=“width=device-width, initial-scale=1.0”>
<head>
<title>Encrypt</title>
<script src="SimpleCrypto.min.js"></script>
</head>
<body>
<script>
var _secretKey = window.AppInventor.getWebViewString().split("||")[0];
var simpleCrypto = new SimpleCrypto(_secretKey);
var plainText = window.AppInventor.getWebViewString().split("||")[1];
var cipherText = simpleCrypto.encrypt(plainText);
window.AppInventor.setWebViewString(cipherText);
</script>
</body>
</html>
decrypt.html
<!DOCTYPE html>
<html>
<meta name=“viewport” content=“width=device-width, initial-scale=1.0”>
<head>
<title>Decrypt</title>
<script src="SimpleCrypto.min.js"></script>
</head>
<body>
<script>
var _secretKey = window.AppInventor.getWebViewString().split("||")[0];
var simpleCrypto = new SimpleCrypto(_secretKey);
var cipherText = window.AppInventor.getWebViewString().split("||")[1];
try {
var decipherText = simpleCrypto.decrypt(cipherText);
window.AppInventor.setWebViewString(decipherText);
}
catch (ex) {
window.AppInventor.setWebViewString("FAIL");
}
</script>
</body>
</html>