本文整理汇总了Java中org.bouncycastle.crypto.engines.RijndaelEngine类的典型用法代码示例。如果您正苦于以下问题:Java RijndaelEngine类的具体用法?Java RijndaelEngine怎么用?Java RijndaelEngine使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RijndaelEngine类属于org.bouncycastle.crypto.engines包,在下文中一共展示了RijndaelEngine类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEncryptRijndael
import org.bouncycastle.crypto.engines.RijndaelEngine; //导入依赖的package包/类
public String testEncryptRijndael(String value,String key) throws DataLengthException, IllegalStateException, InvalidCipherTextException {
BlockCipher engine = new RijndaelEngine(256);
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine), new ZeroBytePadding());
byte[] keyBytes = key.getBytes();
cipher.init(true, new KeyParameter(keyBytes));
byte[] input = value.getBytes();
byte[] cipherText = new byte[cipher.getOutputSize(input.length)];
int cipherLength = cipher.processBytes(input, 0, input.length, cipherText, 0);
cipher.doFinal(cipherText, cipherLength);
String result = new String(Base64.encode(cipherText));
//Log.e("testEncryptRijndael : " , result);
return result;
}
示例2: encrypt
import org.bouncycastle.crypto.engines.RijndaelEngine; //导入依赖的package包/类
public void encrypt(byte[] passiveCheckBytes, byte[] initVector, String password) {
RijndaelEngine engine = new RijndaelEngine(_keyByteLength * 8);
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CFBBlockCipher(engine, 8), new ZeroBytePadding());
try {
byte[] sessionKey = new byte[_keyByteLength];
byte[] passwordBytes = password.getBytes("US-ASCII");
System.arraycopy(passwordBytes, 0, sessionKey, 0, Math.min(_keyByteLength, passwordBytes.length));
byte[] iv = new byte[_keyByteLength];
System.arraycopy(initVector, 0, iv, 0, Math.min(_keyByteLength, initVector.length));
cipher.init(true, new ParametersWithIV(new KeyParameter(sessionKey), iv));
byte[] cipherText = new byte[cipher.getOutputSize(passiveCheckBytes.length)];
int cipherLength = cipher.processBytes(passiveCheckBytes, 0, passiveCheckBytes.length, cipherText, 0);
cipherLength = cipherLength + cipher.doFinal(cipherText, cipherLength);
int bytesToCopy = Math.min(passiveCheckBytes.length, cipherLength);
System.arraycopy(cipherText, 0, passiveCheckBytes, 0, bytesToCopy);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: setParameters
import org.bouncycastle.crypto.engines.RijndaelEngine; //导入依赖的package包/类
public void setParameters(int KeySize, int alg) throws NoSuchAlgorithmException, InvalidKeySpecException
{
switch (alg)
{
case 7:
case 1:
this.blockSize = KeySize;
break;
case 8:
this.blockSize = 256;
break;
default:
this.blockSize = 128;
break;
}
switch (KeySize)
{
case 128:
case 192:
Algs[1] = new RijndaelEngine(KeySize);
break;
case 256:
Algs[1] = new RijndaelEngine(KeySize);
Algs[7] = new ThreefishEngine(KeySize);
break;
default:
Algs[7] = new ThreefishEngine(KeySize);
break;
}
padding = new PKCS7Padding();
}
示例4: ECB
import org.bouncycastle.crypto.engines.RijndaelEngine; //导入依赖的package包/类
public ECB()
{
super(new BlockCipherProvider()
{
public BlockCipher get()
{
return new RijndaelEngine();
}
});
}
示例5: testDecryptRijndael
import org.bouncycastle.crypto.engines.RijndaelEngine; //导入依赖的package包/类
public String testDecryptRijndael(String value,String key) throws DataLengthException, IllegalStateException, InvalidCipherTextException {
BlockCipher engine = new RijndaelEngine(256);
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine), new ZeroBytePadding());
byte[] keyBytes = key.getBytes();
cipher.init(false, new KeyParameter(keyBytes));
byte[] output = Base64.decode(value.getBytes());
byte[] cipherText = new byte[cipher.getOutputSize(output.length)];
int cipherLength = cipher.processBytes(output, 0, output.length, cipherText, 0);
int outputLength = cipher.doFinal(cipherText, cipherLength);
outputLength += cipherLength;
byte[] resultBytes = cipherText;
if (outputLength != output.length) {
resultBytes = new byte[outputLength];
System.arraycopy(
cipherText, 0,
resultBytes, 0,
outputLength
);
}
String result = new String(resultBytes);
return result;
}
示例6: RijndaelTest
import org.bouncycastle.crypto.engines.RijndaelEngine; //导入依赖的package包/类
RijndaelTest()
{
super(tests, new RijndaelEngine(128), new KeyParameter(new byte[16]));
}
示例7: createCipher
import org.bouncycastle.crypto.engines.RijndaelEngine; //导入依赖的package包/类
private BufferedBlockCipher createCipher( boolean encryptor, byte[] key, byte[] iv ) {
BufferedBlockCipher cipher = new BufferedBlockCipher( new CFBBlockCipher( new RijndaelEngine( 128 ), 8 ) );
cipher.init( encryptor, new ParametersWithIV( new KeyParameter( key ), iv ) );
return cipher;
}