use of com.facebook.android.crypto.keychain.AndroidCryptoLibrary in project conceal by facebook.
the class Cipher128BitsTest method testCase.
public void testCase(String key, String iv, String plain, String cipher) throws Exception {
// Test Case 16 - Page 40
KeyChain keyChain = fixedKeyChain(key, iv);
CryptoConfig config = CryptoConfig.KEY_128;
Crypto crypto = new Crypto(keyChain, new AndroidCryptoLibrary(), config);
byte[] plainBytes = toBytes(plain);
byte[] encrypted = crypto.encrypt(plainBytes, new Entity("whatever"));
byte[] expected = toBytes(cipher);
// remove initial 2 bytes + IV
// remove final tag 16 bytes
int metadataLength = config.getHeaderLength() + config.getTailLength();
int prefix = metadataLength - config.tagLength;
byte[] bareEncrypted = Arrays.copyOfRange(encrypted, prefix, encrypted.length - config.tagLength);
Assert.assertTrue(Arrays.equals(expected, bareEncrypted));
}
use of com.facebook.android.crypto.keychain.AndroidCryptoLibrary in project conceal by facebook.
the class EntityFactoryTest method testCase.
public void testCase(String key, String iv, String plain, String entityId) throws Exception {
// Test Case 16 - Page 40
KeyChain keyChain = fixedKeyChain(key, iv);
CryptoConfig config = CryptoConfig.KEY_256;
Crypto crypto = new Crypto(keyChain, new AndroidCryptoLibrary(), config);
byte[] plainBytes = toBytes(plain);
byte[] encrypted = crypto.encrypt(plainBytes, Entity.create(entityId));
byte[] decrypted = crypto.decrypt(encrypted, Entity.create(entityId));
Assert.assertFalse(Arrays.equals(encrypted, plainBytes));
Assert.assertTrue(Arrays.equals(decrypted, plainBytes));
try {
crypto.decrypt(encrypted, Entity.utf16(entityId));
Assert.fail("Decryption with old entity should have failed!");
} catch (IOException ioe) {
// ok, it shouldn't match!
}
}
use of com.facebook.android.crypto.keychain.AndroidCryptoLibrary in project conceal by facebook.
the class Cipher256BitsTest method testCase.
public void testCase(String key, String iv, String plain, String cipher) throws Exception {
// Test Case 16 - Page 40
KeyChain keyChain = fixedKeyChain(key, iv);
CryptoConfig config = CryptoConfig.KEY_256;
Crypto crypto = new Crypto(keyChain, new AndroidCryptoLibrary(), config);
byte[] plainBytes = toBytes(plain);
byte[] encrypted = crypto.encrypt(plainBytes, new Entity("whatever"));
byte[] expected = toBytes(cipher);
// remove initial 2 bytes + IV
// remove final tag 16 bytes
int prefix = config.getHeaderLength();
int metadataLength = config.getHeaderLength() + config.getTailLength();
byte[] bareEncrypted = Arrays.copyOfRange(encrypted, prefix, encrypted.length - config.tagLength);
Assert.assertTrue(Arrays.equals(expected, bareEncrypted));
}
Aggregations