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;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import android.annotation.TargetApi;
import android.os.Build;
import com.facebook.crypto.cipher.NativeGCMCipher;
import org.spongycastle.crypto.InvalidCipherTextException;
import org.spongycastle.crypto.engines.AESEngine;
import org.spongycastle.crypto.modes.GCMBlockCipher;
import org.spongycastle.crypto.params.AEADParameters;
import org.spongycastle.crypto.params.KeyParameter;
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
publicclass BouncyCastleHelper {
publicstatic Result bouncyCastleEncrypt(byte[] data, byte[] key, byte[] iv, byte[] aadData)
throws UnsupportedEncodingException, InvalidCipherTextException {
GCMBlockCipher gcm = new GCMBlockCipher(new AESEngine());
byte[] gcmOut = newbyte[CryptoTestUtils.NUM_DATA_BYTES + NativeGCMCipher.TAG_LENGTH];
KeyParameter keyParameter = new KeyParameter(key);
// Add aad data.
AEADParameters params = new AEADParameters(
keyParameter,
NativeGCMCipher.TAG_LENGTH * 8,
iv,
aadData);
// Init encryption.
gcm.init(true, params);
int written = gcm.processBytes(data, 0, data.length, gcmOut, 0);
written += gcm.doFinal(gcmOut, written);
byte[] bouncyCastleOut = Arrays.copyOfRange(gcmOut, 0, written);
byte[] cipherText =
Arrays.copyOfRange(bouncyCastleOut, 0, CryptoTestUtils.NUM_DATA_BYTES);
byte[] tag =
Arrays.copyOfRange(bouncyCastleOut, CryptoTestUtils.NUM_DATA_BYTES, bouncyCastleOut.length);
returnnew Result(cipherText, tag);
}
publicstaticclass Result {
publicfinalbyte[] cipherText;
publicfinalbyte[] tag;
public Result(byte[] cipherText, byte[] tag) {
this.cipherText = cipherText;
this.tag = tag;
}
}
}