当前位置: 首页>>代码示例>>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;未经允许,请勿转载。