BSD License
For Conceal software
Copyright (c) 2014, Facebook, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that...
If you think the Android project conceal listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (c) 2014, Facebook, Inc.//www.java2s.com
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/package com.facebook.crypto.streams;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec;
import com.google.common.io.ByteStreams;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
publicclass BetterCipherInputStreamTest {
privatebyte[] mData;
privatebyte[] mCipheredData;
private Key mKey;
private AlgorithmParameterSpec mIV;
privatestaticfinal String CIPHER_ALG = "AES/CTR/NoPadding";
@Before
publicvoid setUp() throws Exception {
mData = newbyte[1024 * 1024];
mCipheredData = newbyte[mData.length];
byte[] iv = newbyte[16];
byte[] key = newbyte[16];
mKey = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance(CIPHER_ALG);
mIV = new IvParameterSpec(iv);
cipher.init(Cipher.ENCRYPT_MODE, mKey, mIV);
mCipheredData = cipher.update(mData, 0, mData.length);
cipher.doFinal();
}
@Test
publicvoid testDecryptsCorrectly() throws Exception {
ByteArrayInputStream input = new ByteArrayInputStream(mCipheredData);
BetterCipherInputStream cipherStream = new BetterCipherInputStream(input, getDecrypt());
byte[] decryptedBytes = ByteStreams.toByteArray(cipherStream);
Assert.assertArrayEquals(decryptedBytes, mData);
}
private Cipher getDecrypt() throws Exception {
Cipher cipher = Cipher.getInstance(CIPHER_ALG);
cipher.init(Cipher.DECRYPT_MODE, mKey, mIV);
return cipher;
}
}