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.//fromwww.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.benchmarks.cipher;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.SecureRandom;
import com.facebook.crypto.benchmarks.BenchmarkNativeCryptoLibrary;
import com.facebook.crypto.cipher.NativeGCMCipher;
import com.facebook.crypto.util.NativeCryptoLibrary;
import com.facebook.crypto.exception.CryptoInitializationException;
import com.facebook.crypto.streams.NativeGCMCipherInputStream;
import com.facebook.crypto.streams.NativeGCMCipherOutputStream;
publicclass NativeGCMCipherHelper {
privatestaticfinal NativeCryptoLibrary mNativeCryptoLibrary =
new BenchmarkNativeCryptoLibrary();
privatebyte[] mKey;
privatebyte[] mIv;
public NativeGCMCipherHelper(byte[] key, byte[] iv) {
this.mKey = key.clone();
this.mIv = iv.clone();
}
publicstatic NativeGCMCipherHelper getInstance() {
byte[] key = newbyte[NativeGCMCipher.KEY_LENGTH];
byte[] iv = newbyte[NativeGCMCipher.IV_LENGTH];
new SecureRandom().nextBytes(key);
new SecureRandom().nextBytes(iv);
returnnew NativeGCMCipherHelper(key, iv);
}
public OutputStream getOutputStream(OutputStream cipherStream)
throws IOException, CryptoInitializationException {
NativeGCMCipher gcmCipher = new NativeGCMCipher(mNativeCryptoLibrary);
gcmCipher.encryptInit(mKey, mIv);
cipherStream.write(mIv);
returnnew NativeGCMCipherOutputStream(cipherStream, gcmCipher);
}
public InputStream getInputStream(InputStream cipherStream)
throws IOException, CryptoInitializationException {
byte[] iv = newbyte[NativeGCMCipher.IV_LENGTH];
cipherStream.read(iv);
NativeGCMCipher gcmCipher = new NativeGCMCipher(mNativeCryptoLibrary);
gcmCipher.decryptInit(mKey, iv);
returnnew NativeGCMCipherInputStream(cipherStream, gcmCipher);
}
}