當前位置: 首頁>>代碼示例>>Java>>正文


Java BufferedBlockCipher.processBytes方法代碼示例

本文整理匯總了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;
    }
 
開發者ID:timerickson,項目名稱:lastpass-java,代碼行數:27,代碼來源:SimpleAesManaged.java

示例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);
    }
}
 
開發者ID:timerickson,項目名稱:lastpass-java,代碼行數:18,代碼來源:ParserHelperTest.java

示例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;
}
 
開發者ID:David-Hackro,項目名稱:ExamplesAndroid,代碼行數:18,代碼來源:Metodos.java

示例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;
  }
 
開發者ID:PacktPublishing,項目名稱:Spring-MVC-Blueprints,代碼行數:17,代碼來源:UploadEncryptFileController.java

示例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);
            }
        }
    };
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:26,代碼來源:BcPBESecretKeyDecryptorBuilder.java

示例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);
    }
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:22,代碼來源:BcPBEKeyEncryptionMethodGenerator.java

示例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)));
    }
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:17,代碼來源:ResetTest.java

示例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;
}
 
開發者ID:GoMint,項目名稱:GoMint,代碼行數:17,代碼來源:EncryptionHandler.java

示例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;
	}
 
開發者ID:nresare,項目名稱:javapasswordsafe,代碼行數:17,代碼來源:TwofishPws.java

示例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;
}
 
開發者ID:ScripterRon,項目名稱:BitcoinCore,代碼行數:32,代碼來源:EncryptedPrivateKey.java

示例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;
    }

}
 
開發者ID:dimagi,項目名稱:commcare-j2me,代碼行數:22,代碼來源:CryptUtil.java

示例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;
}
 
開發者ID:sblit,項目名稱:sblit,代碼行數:17,代碼來源:SymmetricEncryption.java

示例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;
}
 
開發者ID:hdsdi3g,項目名稱:MyDMAM,代碼行數:18,代碼來源:Password.java

示例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);
}
 
開發者ID:christian-schlichtherle,項目名稱:truevfs,代碼行數:22,代碼來源:CipherOutputStream.java

示例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;
}
 
開發者ID:JungleTree,項目名稱:JungleTree,代碼行數:16,代碼來源:ProtocolEncryption.java


注:本文中的org.bouncycastle.crypto.BufferedBlockCipher.processBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。