本文整理匯總了Java中org.bouncycastle.crypto.BufferedBlockCipher.processBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java BufferedBlockCipher.processBytes方法的具體用法?Java BufferedBlockCipher.processBytes怎麽用?Java BufferedBlockCipher.processBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bouncycastle.crypto.BufferedBlockCipher
的用法示例。
在下文中一共展示了BufferedBlockCipher.processBytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decrypt
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
@Override
public String decrypt(byte[] encrypted) {
// Cipher cipher = null;
String plain;
try {
// Security.addProvider(new BouncyCastlePQCProvider());
// cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", new BouncyCastlePQCProvider());
// cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(encryptionKey, "AES"), new IvParameterSpec(iv));
// plain = new String(cipher.doFinal(encrypted), "UTF-8");
KeyParameter keyParam = new KeyParameter(encryptionKey);
CipherParameters params = new ParametersWithIV(keyParam, iv);
BlockCipherPadding padding = new PKCS7Padding();
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(
new CBCBlockCipher(new AESEngine()), padding);
cipher.reset();
cipher.init(false, params);
byte[] buffer = new byte[cipher.getOutputSize(encrypted.length)];
int len = cipher.processBytes(encrypted, 0, encrypted.length, buffer, 0);
len += cipher.doFinal(buffer, len);
byte[] out = Arrays.copyOfRange(buffer, 0, len);
plain = new String(out, "UTF-8");
} catch (Exception e) {
throw new RuntimeException("decrypt error in SimpleAesManaged", e);
}
return plain;
}
示例2: EncryptAes256
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private static byte[] EncryptAes256(byte[] data, byte[] encryptionKey)
{
try {
KeyParameter keyParam = new KeyParameter(encryptionKey);
BlockCipherPadding padding = new PKCS7Padding();
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(
new CBCBlockCipher(new AESEngine()), padding);
cipher.reset();
cipher.init(true, keyParam);
byte[] buffer = new byte[cipher.getOutputSize(data.length)];
int len = cipher.processBytes(data, 0, data.length, buffer, 0);
len += cipher.doFinal(buffer, len);
return Arrays.copyOfRange(buffer, 0, len);
} catch (Exception e) {
throw new RuntimeException("decrypt error in SimpleAesManaged", e);
}
}
示例3: testEncryptRijndael
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的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;
}
示例4: encryptDESFile
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private byte[] encryptDESFile(String keys, byte[] plainText) {
BlockCipher engine = new DESEngine();
byte[] key = keys.getBytes();
byte[] ptBytes = plainText;
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine));
cipher.init(true, new KeyParameter(key));
byte[] rv = new byte[cipher.getOutputSize(ptBytes.length)];
int tam = cipher.processBytes(ptBytes, 0, ptBytes.length, rv, 0);
try {
cipher.doFinal(rv, tam);
} catch (Exception ce) {
ce.printStackTrace();
}
return rv;
}
示例5: build
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
public PBESecretKeyDecryptor build(char[] passPhrase)
{
return new PBESecretKeyDecryptor(passPhrase, calculatorProvider)
{
public byte[] recoverKeyData(int encAlgorithm, byte[] key, byte[] iv, byte[] keyData, int keyOff, int keyLen)
throws PGPException
{
try
{
BufferedBlockCipher c = BcUtil.createSymmetricKeyWrapper(false, BcImplProvider.createBlockCipher(encAlgorithm), key, iv);
byte[] out = new byte[keyLen];
int outLen = c.processBytes(keyData, keyOff, keyLen, out, 0);
outLen += c.doFinal(out, outLen);
return out;
}
catch (InvalidCipherTextException e)
{
throw new PGPException("decryption failed: " + e.getMessage(), e);
}
}
};
}
示例6: encryptSessionInfo
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
protected byte[] encryptSessionInfo(int encAlgorithm, byte[] key, byte[] sessionInfo)
throws PGPException
{
try
{
BlockCipher engine = BcImplProvider.createBlockCipher(encAlgorithm);
BufferedBlockCipher cipher = BcUtil.createSymmetricKeyWrapper(true, engine, key, new byte[engine.getBlockSize()]);
byte[] out = new byte[sessionInfo.length];
int len = cipher.processBytes(sessionInfo, 0, sessionInfo.length, out, 0);
len += cipher.doFinal(out, len);
return out;
}
catch (InvalidCipherTextException e)
{
throw new PGPException("encryption failed: " + e.getMessage(), e);
}
}
示例7: basicTrial
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private void basicTrial(BufferedBlockCipher cipher, KeyParameter param)
throws InvalidCipherTextException
{
cipher.init(true, param);
byte[] out = new byte[input.length];
int len1 = cipher.processBytes(input, 0, input.length, out, 0);
cipher.doFinal(out, len1);
if (!areEqual(out, output))
{
fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out)));
}
}
示例8: processCipher
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private byte[] processCipher( BufferedBlockCipher cipher, byte[] input ) {
byte[] output = new byte[cipher.getOutputSize( input.length )];
int cursor = cipher.processBytes( input, 0, input.length, output, 0 );
try {
// cursor += cipher.doFinal( output, cursor );
if ( cursor != output.length ) {
throw new InvalidCipherTextException( "Output size did not match cursor" );
}
} catch ( InvalidCipherTextException e ) {
LOGGER.error( "Could not encrypt/decrypt to/from cipher-text", e );
return null;
}
return output;
}
示例9: processECB
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
public static byte[] processECB(byte[] key, boolean forEncryption, byte[] input) {
final BufferedBlockCipher cipher = new BufferedBlockCipher(new TwofishEngine());
final KeyParameter kp = new KeyParameter(key);
cipher.init(forEncryption, kp);
final byte[] out = new byte[input.length];
final int len1 = cipher.processBytes(input, 0, input.length, out, 0);
try {
cipher.doFinal(out, len1);
} catch (final CryptoException e) {
throw new RuntimeException(e);
}
return out;
}
示例10: getPrivKey
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
/**
* Returns the decrypted private key
*
* @param keyPhrase Key phrase used to derive the encryption key
* @return Private key
* @throws ECException Unable to complete a cryptographic function
*/
public BigInteger getPrivKey(String keyPhrase) throws ECException {
KeyParameter aesKey = deriveKey(keyPhrase, salt);
//
// Decrypt the private key using the generated AES key
//
BigInteger privKey;
try {
ParametersWithIV keyWithIV = new ParametersWithIV(aesKey, iv);
CBCBlockCipher blockCipher = new CBCBlockCipher(new AESEngine());
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(blockCipher);
cipher.init(false, keyWithIV);
int bufferLength = cipher.getOutputSize(encKeyBytes.length);
byte[] outputBytes = new byte[bufferLength];
int length1 = cipher.processBytes(encKeyBytes, 0, encKeyBytes.length, outputBytes, 0);
int length2 = cipher.doFinal(outputBytes, length1);
int actualLength = length1 + length2;
byte[] privKeyBytes = new byte[actualLength];
System.arraycopy(outputBytes, 0, privKeyBytes, 0, actualLength);
privKey = new BigInteger(privKeyBytes);
} catch (Exception exc) {
throw new ECException("Unable to decrypt the private key", exc);
}
return privKey;
}
示例11: encrypt
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
public static byte[] encrypt(byte[] input, BufferedBlockCipher cipher) {
synchronized(cipher) {
cipher.reset();
byte[] cipherText = new byte[cipher.getOutputSize(input.length + pad.length)];
//Write out the pad
int outputLen = cipher.processBytes(pad, 0, pad.length, cipherText, 0);
outputLen += cipher.processBytes(input, 0, input.length, cipherText, outputLen);
try {
cipher.doFinal(cipherText, outputLen);
} catch(CryptoException e) {
Logger.die("process", e);
}
return cipherText;
}
}
示例12: process
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private byte[] process(byte[] data, boolean encryption) throws DataLengthException {
BlockCipher cipher = new AESEngine();
BlockCipherPadding padding = new ZeroBytePadding();
BufferedBlockCipher bufferedCipher = new PaddedBufferedBlockCipher(cipher, padding);
bufferedCipher.init(encryption, key);
byte[] output = new byte[bufferedCipher.getOutputSize(data.length)];
int bytesProcessed = bufferedCipher.processBytes(data, 0, data.length, output, 0);
try {
bufferedCipher.doFinal(output, bytesProcessed);
return output;
} catch (IllegalStateException
| InvalidCipherTextException e) {
e.printStackTrace();
}
return null;
}
示例13: checkPassword
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
public boolean checkPassword(String candidate_password, byte[] raw_password) {
try {
BlockCipherPadding padding = new PKCS7Padding();
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), padding);
cipher.reset();
cipher.init(false, params);
byte[] buf = new byte[cipher.getOutputSize(raw_password.length)];
int len = cipher.processBytes(raw_password, 0, raw_password.length, buf, 0);
len += cipher.doFinal(buf, len);
return BCrypt.checkpw(candidate_password, new String(buf, 0, len));
} catch (Exception e) {
Loggers.Auth.error("Can't extract hashed password", e);
}
return false;
}
示例14: write
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
/**
* Ciphers and writes the contents of the given byte array to the
* underlying output stream.
*
* @param buf The buffer holding the data to cipher and write.
* @param off The start offset of the data in the buffer.
* @param len The number of bytes to cipher and write.
* @throws IOException If out or cipher aren't properly initialized,
* the stream has been closed or an I/O error occured.
*/
@Override
public void write(final byte[] buf, final int off, final int len)
throws IOException {
final BufferedBlockCipher cipher = cipher();
int cipherLen = cipher.getUpdateOutputSize(len);
byte[] cipherOut = this.buffer;
if (cipherLen > cipherOut.length)
this.buffer = cipherOut = new byte[cipherLen];
cipherLen = cipher.processBytes(buf, off, len, cipherOut, 0);
out.write(cipherOut, 0, cipherLen);
}
示例15: processCipher
import org.bouncycastle.crypto.BufferedBlockCipher; //導入方法依賴的package包/類
private byte[] processCipher(BufferedBlockCipher cipher, byte[] input) {
byte[] output = new byte[cipher.getOutputSize(input.length)];
int cursor = cipher.processBytes(input, 0, input.length, output, 0);
try {
if (cursor != output.length) {
throw new InvalidCipherTextException("Output size did not match cursor");
}
} catch (InvalidCipherTextException e) {
log.error("Could not encrypt/decrypt to/from cipher-text", e);
return null;
}
return output;
}