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


Java BufferedBlockCipher類代碼示例

本文整理匯總了Java中org.bouncycastle.crypto.BufferedBlockCipher的典型用法代碼示例。如果您正苦於以下問題:Java BufferedBlockCipher類的具體用法?Java BufferedBlockCipher怎麽用?Java BufferedBlockCipher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BufferedBlockCipher類屬於org.bouncycastle.crypto包,在下文中一共展示了BufferedBlockCipher類的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: finish

import org.bouncycastle.crypto.BufferedBlockCipher; //導入依賴的package包/類
/**
 * Finishes and voids this cipher output stream.
 * Calling this method causes all remaining buffered bytes to get written
 * and padded if necessary.
 * Afterwards, this stream will behave as if it had been closed, although
 * the decorated stream may still be open.
 *
 * @throws IOException If {@code out} or {@code cipher} aren't properly
 *         initialized, an I/O error occurs or the cipher
 *         text is invalid because some required padding is missing.
 */
public void finish() throws IOException {
    final BufferedBlockCipher cipher = this.cipher;
    if (null == cipher)
        return;
    this.cipher = null;

    int cipherLen = cipher.getOutputSize(0);
    byte[] cipherOut = this.buffer;
    if (cipherLen > cipherOut.length)
        this.buffer = cipherOut = new byte[cipherLen];
    try {
        cipherLen = cipher.doFinal(cipherOut, 0);
    } catch (InvalidCipherTextException ex) {
        throw new IOException(ex);
    }
    out.write(cipherOut, 0, cipherLen);
}
 
開發者ID:christian-schlichtherle,項目名稱:truevfs,代碼行數:29,代碼來源:CipherOutputStream.java

示例6: createDataDecryptor

import org.bouncycastle.crypto.BufferedBlockCipher; //導入依賴的package包/類
public static PGPDataDecryptor createDataDecryptor(boolean withIntegrityPacket, BlockCipher engine, byte[] key)
{
    final BufferedBlockCipher c = createStreamCipher(false, engine, withIntegrityPacket, key);

    return new PGPDataDecryptor()
    {
        public InputStream getInputStream(InputStream in)
        {
            return new CipherInputStream(in, c);
        }

        public int getBlockSize()
        {
            return c.getBlockSize();
        }

        public PGPDigestCalculator getIntegrityCalculator()
        {
            return new SHA1PGPDigestCalculator();
        }
    };
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:23,代碼來源:BcUtil.java

示例7: 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

示例8: 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

示例9: createCipherInputStream

import org.bouncycastle.crypto.BufferedBlockCipher; //導入依賴的package包/類
private InputStream createCipherInputStream(byte[] data, Object cipher)
{
    ByteArrayInputStream input = new ByteArrayInputStream(data);
    if (cipher instanceof BufferedBlockCipher)
    {
        return new CipherInputStream(input, (BufferedBlockCipher)cipher);
    }
    else if (cipher instanceof AEADBlockCipher)
    {
        return new CipherInputStream(input, (AEADBlockCipher)cipher);
    }
    else
    {
        return new CipherInputStream(input, (StreamCipher)cipher);
    }
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:17,代碼來源:CipherStreamTest.java

示例10: getName

import org.bouncycastle.crypto.BufferedBlockCipher; //導入依賴的package包/類
private String getName(Object cipher)
{
    if (cipher instanceof BufferedBlockCipher)
    {
        return ((BufferedBlockCipher)cipher).getUnderlyingCipher().getAlgorithmName();
    }
    else if (cipher instanceof AEADBlockCipher)
    {
        return ((AEADBlockCipher)cipher).getUnderlyingCipher().getAlgorithmName();
    }
    else if (cipher instanceof StreamCipher)
    {
        return ((StreamCipher)cipher).getAlgorithmName();
    }
    return null;
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:17,代碼來源:CipherStreamTest.java

示例11: getBlockSize

import org.bouncycastle.crypto.BufferedBlockCipher; //導入依賴的package包/類
private int getBlockSize(Object cipher)
{
    if (cipher instanceof BlockCipher)
    {
        return ((BlockCipher)cipher).getBlockSize();
    }
    else if (cipher instanceof BufferedBlockCipher)
    {
        return ((BufferedBlockCipher)cipher).getBlockSize();
    }
    else if (cipher instanceof AEADBlockCipher)
    {
        return ((AEADBlockCipher)cipher).getUnderlyingCipher().getBlockSize();
    }
    else if (cipher instanceof StreamCipher)
    {
        return 1;
    }
    return 0;
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:21,代碼來源:CipherStreamTest.java

示例12: 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

示例13: 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

示例14: 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

示例15: MultilayeredOutputStream

import org.bouncycastle.crypto.BufferedBlockCipher; //導入依賴的package包/類
public MultilayeredOutputStream(ArchiveInfoContext context, FileInventoryItem target) throws FileNotFoundException
{
    this.target = target;
    this.topstream = new BlockWriterOutputStream(
                context.filePath,
                context.getBlockSize(),
                target,
                new BlockAllocationManager(context.getInventory(), target.getBlocks())
    );

    target.setEncryptionAlgorithm(context.getInventory().getDefaultEncryption());

    if (target.isEncrypted())
    {
        this.topstream = new CipherOutputStream(
                this.topstream, new BufferedBlockCipher(CipherBuilder.buildCipherForFile(target, true))
        );
    }
    else
    {
        target.setEncryptionData(null);
    }

    this.topstream = new DeflaterOutputStream(this.topstream, new Deflater(Deflater.BEST_SPEED));
}
 
開發者ID:AstromechZA,項目名稱:bunkr,代碼行數:26,代碼來源:MultilayeredOutputStream.java


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