Skip to content

Instantly share code, notes, and snippets.

@secondsun
Created November 8, 2013 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secondsun/c1fb32a4c49f9bb6bed2 to your computer and use it in GitHub Desktop.
Save secondsun/c1fb32a4c49f9bb6bed2 to your computer and use it in GitHub Desktop.
Encryption Services usage examples
PassPhraseKeyServices.PassPhraseCryptoConfig config = new PassPhraseKeyServices.PassPhraseCryptoConfig();
config.setPassphrase("testPhrase");
config.setSalt(SALT);
PassPhraseKeyServices service = new PassPhraseKeyServices(getActivity(), config);
String message = "This is a test message";
byte[] encrypted = service.encrypt(message.getBytes());
byte[] decrypted = service.decrypt(encrypted);
assertTrue(Arrays.equals(decrypted, message.getBytes()));
String message = "This is a test message";
PasswordKeyServices.PasswordProtectedKeystoreCryptoConfig config = new PasswordKeyServices.PasswordProtectedKeystoreCryptoConfig();
config.setAlias("TestAlias");
config.setPassword("testPhrase");
PasswordKeyServices service = new PasswordKeyServices(config, getActivity());
byte[] encrypted = service.encrypt(TestVectors.CRYPTOBOX_IV.getBytes(), message.getBytes());
assertFalse(Arrays.equals(encrypted, message.getBytes()));
byte[] decrypted = service.decrypt(TestVectors.CRYPTOBOX_IV.getBytes(), encrypted);
assertTrue(Arrays.equals(decrypted, message.getBytes()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment