Skip to content

Instantly share code, notes, and snippets.

@MichalGniadek
Last active November 21, 2023 13:27
Show Gist options
  • Save MichalGniadek/f48a05ae2008203ce3ef92235cb7bc49 to your computer and use it in GitHub Desktop.
Save MichalGniadek/f48a05ae2008203ce3ef92235cb7bc49 to your computer and use it in GitHub Desktop.
@Override
public void onMessageReceived(RemoteMessage message) {
try {
AESCryptoModuleCompat obj = new AESCryptoModuleCompat();
byte[] key = obj.generateKey();
String plaintext = "test_data!";
byte[] sealedData =
obj.encrypt(key, plaintext.getBytes(StandardCharsets.UTF_8));
String decrypted =
new String(obj.decrypt(key, sealedData), StandardCharsets.UTF_8);
Log.w("COMM", "Decrypted text: " + decrypted);
} catch (Exception e) {
Log.w(
"COMM",
"Failed to run generate key -> encrypt -> decrypt sequence.",
e);
}
// ...omitted in gist...
}
import * as AES from '../utils/aes-crypto-module.js';
const key = AES.generateKey();
const plaintext = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
const sealedData = AES.encrypt(key, plaintext);
const plaintext2 = AES.decrypt(key, sealedData);
console.log(`
key: ${key.toString()}
plaintext: ${plaintext.toString()}
sealedData: ${sealedData.toString()}
plaintext2: ${plaintext2.toString()}
`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment