本文整理汇总了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 );
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}