当前位置: 首页>>代码示例>>Java>>正文


Java Streams类代码示例

本文整理汇总了Java中org.bouncycastle.util.io.Streams的典型用法代码示例。如果您正苦于以下问题:Java Streams类的具体用法?Java Streams怎么用?Java Streams使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Streams类属于org.bouncycastle.util.io包,在下文中一共展示了Streams类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encrypt

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
public static byte[] encrypt( final byte[] message, final PGPPublicKey publicKey, boolean armored )
        throws PGPException
{
    try
    {
        final ByteArrayInputStream in = new ByteArrayInputStream( message );
        final ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        final PGPLiteralDataGenerator literal = new PGPLiteralDataGenerator();
        final PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator( CompressionAlgorithmTags.ZIP );
        final OutputStream pOut =
                literal.open( comData.open( bOut ), PGPLiteralData.BINARY, "filename", in.available(), new Date() );
        Streams.pipeAll( in, pOut );
        comData.close();
        final byte[] bytes = bOut.toByteArray();
        final PGPEncryptedDataGenerator generator = new PGPEncryptedDataGenerator(
                new JcePGPDataEncryptorBuilder( SymmetricKeyAlgorithmTags.AES_256 ).setWithIntegrityPacket( true )
                                                                                   .setSecureRandom(
                                                                                           new SecureRandom() )

                                                                                   .setProvider( provider ) );
        generator.addMethod( new JcePublicKeyKeyEncryptionMethodGenerator( publicKey ).setProvider( provider ) );
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        OutputStream theOut = armored ? new ArmoredOutputStream( out ) : out;
        OutputStream cOut = generator.open( theOut, bytes.length );
        cOut.write( bytes );
        cOut.close();
        theOut.close();
        return out.toByteArray();
    }
    catch ( Exception e )
    {
        throw new PGPException( "Error in encrypt", e );
    }
}
 
开发者ID:subutai-io,项目名称:base,代码行数:35,代码来源:PGPEncryptionUtil.java

示例2: encryptReply

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
public EncryptedResponsePacket encryptReply(String aesKey, InputStream plaintext) throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException, IOException {
    byte[] keyBytes = Base64.decode(aesKey);

    SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");

    Cipher cipher = Cipher.getInstance("AES/CCM/NoPadding", "BC");
    cipher.init(Cipher.ENCRYPT_MODE, key, new SecureRandom());
    byte[] iv = cipher.getIV();

    ByteArrayOutputStream encrypted = new ByteArrayOutputStream();


    CipherOutputStream cOut = new CipherOutputStream(encrypted, cipher);
    Streams.pipeAll(plaintext, cOut);
    cOut.close();

    EncryptedResponsePacket packet = new EncryptedResponsePacket();
    packet.iv = Base64.toBase64String(iv);
    packet.mode = "ccm";
    packet.ct = Base64.toBase64String(encrypted.toByteArray());

    return packet;
}
 
开发者ID:Tethik,项目名称:whistleblower,代码行数:24,代码来源:CryptographyHandler.java

示例3: toByteArray

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
byte[] toByteArray()
    throws IOException
{
    if (_remaining == 0)
    {
        return EMPTY_BYTES;
    }

    byte[] bytes = new byte[_remaining];
    if ((_remaining -= Streams.readFully(_in, bytes)) != 0)
    {
        throw new EOFException("DEF length " + _originalLength + " object truncated by " + _remaining);
    }
    setParentEofDetect(true);
    return bytes;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:17,代码来源:DefiniteLengthInputStream.java

示例4: decryptPrivateKeyInfo

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
public PrivateKeyInfo decryptPrivateKeyInfo(InputDecryptorProvider inputDecryptorProvider)
    throws PKCSException
{
    try
    {
        InputDecryptor decrytor = inputDecryptorProvider.get(encryptedPrivateKeyInfo.getEncryptionAlgorithm());

        ByteArrayInputStream encIn = new ByteArrayInputStream(encryptedPrivateKeyInfo.getEncryptedData());

        return PrivateKeyInfo.getInstance(Streams.readAll(decrytor.getInputStream(encIn)));
    }
    catch (Exception e)
    {
        throw new PKCSException("unable to read encrypted data: " + e.getMessage(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:PKCS8EncryptedPrivateKeyInfo.java

示例5: getBuffer

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
private static byte[] getBuffer(DefiniteLengthInputStream defIn, byte[][] tmpBuffers)
    throws IOException
{
    int len = defIn.getRemaining();
    if (defIn.getRemaining() < tmpBuffers.length)
    {
        byte[] buf = tmpBuffers[len];

        if (buf == null)
        {
            buf = tmpBuffers[len] = new byte[len];
        }

        Streams.readFully(defIn, buf);

        return buf;
    }
    else
    {
        return defIn.toByteArray();
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:23,代码来源:ASN1InputStream.java

示例6: fromInputStream

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
static DERBitString fromInputStream(int length, InputStream stream)
    throws IOException
{
    if (length < 1)
    {
        throw new IllegalArgumentException("truncated BIT STRING detected");
    }

    int padBits = stream.read();
    byte[] data = new byte[length - 1];

    if (data.length != 0)
    {
        if (Streams.readFully(stream, data) != data.length)
        {
            throw new EOFException("EOF encountered in middle of BIT STRING");
        }
    }

    return new DERBitString(data, padBits);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:22,代码来源:DERBitString.java

示例7: getMac

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
/**
 * Return the MAC calculated for the recipient. Note: this call is only meaningful once all
 * the content has been read.
 *
 * @return  byte array containing the mac.
 */
public byte[] getMac()
{
    if (resultMac == null)
    {
        if (operator.isMacBased())
        {
            if (additionalData != null)
            {
                try
                {
                    Streams.drain(operator.getInputStream(new ByteArrayInputStream(additionalData.getAuthAttributes().getEncoded(ASN1Encoding.DER))));
                }
                catch (IOException e)
                {
                    throw new IllegalStateException("unable to drain input: " + e.getMessage());
                }
            }
            resultMac = operator.getMac();
        }
    }

    return resultMac;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:30,代码来源:RecipientInformation.java

示例8: parseTimeStamps

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
private void parseTimeStamps()
    throws CMSException
{
    try
    {
        if (util == null)
        {
            InputStream cont = this.getContent();

            if (cont != null)
            {
                Streams.drain(cont);
            }

            util = new TimeStampDataUtil(timeStampedData);
        }
    }
    catch (IOException e)
    {
        throw new CMSException("unable to parse evidence block: " + e.getMessage(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:23,代码来源:CMSTimeStampedDataParser.java

示例9: processClientKeyExchange

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
public void processClientKeyExchange(InputStream input)
    throws IOException
{
    byte[] encryptedPreMasterSecret;
    if (TlsUtils.isSSL(context))
    {
        // TODO Do any SSLv3 clients actually include the length?
        encryptedPreMasterSecret = Streams.readAll(input);
    }
    else
    {
        encryptedPreMasterSecret = TlsUtils.readOpaque16(input);
    }

    this.premasterSecret = serverCredentials.decryptPreMasterSecret(encryptedPreMasterSecret);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:17,代码来源:TlsRSAKeyExchange.java

示例10: readAllOrNothing

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
public static byte[] readAllOrNothing(int length, InputStream input)
    throws IOException
{
    if (length < 1)
    {
        return EMPTY_BYTES;
    }
    byte[] buf = new byte[length];
    int read = Streams.readFully(input, buf);
    if (read == 0)
    {
        return null;
    }
    if (read != length)
    {
        throw new EOFException();
    }
    return buf;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:20,代码来源:TlsUtils.java

示例11: processClientKeyExchange

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
public void processClientKeyExchange(InputStream input)
    throws IOException
{
    byte[] encryptedPreMasterSecret;
    if (TlsUtils.isSSL(context))
    {
        // TODO Do any SSLv3 clients actually include the length?
        encryptedPreMasterSecret = Streams.readAll(input);
    }
    else
    {
        encryptedPreMasterSecret = TlsUtils.readOpaque16(input);
    }

    this.premasterSecret = TlsRSAUtils.safeDecryptPreMasterSecret(context, serverCredentials, encryptedPreMasterSecret);
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:17,代码来源:TlsRSAKeyExchange.java

示例12: getMac

import org.bouncycastle.util.io.Streams; //导入依赖的package包/类
/**
 * Return the MAC calculated for the recipient. Note: this call is only meaningful once all
 * the content has been read.
 *
 * @return  byte array containing the mac.
 */
public byte[] getMac()
{
    if (resultMac == null)
    {
        if (operator.isMacBased())
        {
            if (additionalData != null)
            {
                try
                {
                    Streams.drain(operator.getInputStream(new ByteArrayInputStream(additionalData.getAuthAttributes().getEncoded(ASN1Encoding.DER))));
                }
                catch (IOException e)
                {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
            }
            resultMac = operator.getMac();
        }
    }

    return resultMac;
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:30,代码来源:RecipientInformation.java


注:本文中的org.bouncycastle.util.io.Streams类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。