本文整理汇总了Java中org.bouncycastle.util.io.Streams.pipeAll方法的典型用法代码示例。如果您正苦于以下问题:Java Streams.pipeAll方法的具体用法?Java Streams.pipeAll怎么用?Java Streams.pipeAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.util.io.Streams
的用法示例。
在下文中一共展示了Streams.pipeAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: testValidateAllTokens
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
public void testValidateAllTokens()
throws Exception
{
DigestCalculatorProvider digestCalculatorProvider = new BcDigestCalculatorProvider();
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
Streams.pipeAll(cmsTimeStampedData.getContent(), bOut);
DigestCalculator imprintCalculator = cmsTimeStampedData.getMessageImprintDigestCalculator(digestCalculatorProvider);
Streams.pipeAll(new ByteArrayInputStream(bOut.toByteArray()), imprintCalculator.getOutputStream());
byte[] digest = imprintCalculator.getDigest();
TimeStampToken[] tokens = cmsTimeStampedData.getTimeStampTokens();
for (int i = 0; i < tokens.length; i++)
{
cmsTimeStampedData.validate(digestCalculatorProvider, digest, tokens[i]);
}
}
示例4: pipeOctetString
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
private static void pipeOctetString(
ASN1OctetStringParser octs,
OutputStream output)
throws IOException
{
// TODO Allow specification of a specific fragment size?
OutputStream outOctets = CMSUtils.createBEROctetOutputStream(
output, 0, true, 0);
Streams.pipeAll(octs.getOctetStream(), outOctets);
outOctets.close();
}
示例5: write
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
public void write(OutputStream zOut)
throws IOException, CMSException
{
checkSingleUsage();
Streams.pipeAll(input, zOut);
input.close();
}
示例6: parse
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
/**
* Parse a {@link HeartbeatMessage} from an {@link InputStream}.
*
* @param input
* the {@link InputStream} to parse from.
* @return a {@link HeartbeatMessage} object.
* @throws IOException
*/
public static HeartbeatMessage parse(InputStream input) throws IOException
{
short type = TlsUtils.readUint8(input);
if (!HeartbeatMessageType.isValid(type))
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
int payload_length = TlsUtils.readUint16(input);
PayloadBuffer buf = new PayloadBuffer();
Streams.pipeAll(input, buf);
byte[] payload = buf.toTruncatedByteArray(payload_length);
if (payload == null)
{
/*
* RFC 6520 4. If the payload_length of a received HeartbeatMessage is too large, the
* received HeartbeatMessage MUST be discarded silently.
*/
return null;
}
int padding_length = buf.size() - payload.length;
/*
* RFC 6520 4. The padding of a received HeartbeatMessage message MUST be ignored
*/
return new HeartbeatMessage(type, payload, padding_length);
}
示例7: decrypt
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
public static byte[] decrypt( final byte[] encryptedMessage, final InputStream secretKeyRing,
final String secretPwd ) throws PGPException
{
try
{
final PGPLiteralData msg = asLiteral( encryptedMessage, secretKeyRing, secretPwd );
final ByteArrayOutputStream out = new ByteArrayOutputStream();
Streams.pipeAll( msg.getInputStream(), out );
return out.toByteArray();
}
catch ( Exception e )
{
throw new PGPException( "Error in decrypt", e );
}
}
示例8: pemFile
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
@Test
public void pemFile() throws IOException {
try (InputStream is = AbstractTestCRLUtils.class.getResourceAsStream("/belgium2.pem.crl")) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Streams.pipeAll(is, baos);
ByteArrayOutputStream convert = PemToDerConverter.convert(baos);
byte[] converted = convert.toByteArray();
assertTrue(converted != null && converted.length > 0);
}
}
示例9: readUserRepoInvitationToken
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
private UserRepoInvitationToken readUserRepoInvitationToken(File file) {
try {
final ByteArrayOutputStream bout = new ByteArrayOutputStream((int) file.length());
try (InputStream in = castStream(file.createInputStream())) {
Streams.pipeAll(in, bout);
}
final UserRepoInvitationToken result = new UserRepoInvitationToken(bout.toByteArray());
return result;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例10: readPayload
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
protected void readPayload(final ZipInputStream zin) throws IOException {
ZipEntry zipEntry;
while (null != (zipEntry = zin.getNextEntry())) {
final String name = zipEntry.getName();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
Streams.pipeAll(zin, out);
name2ByteArray.put(name, out.toByteArray());
}
}
示例11: getData
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
protected byte[] getData(final File file, final LockFile lockFile) throws IOException {
try (final InputStream in = castStream(lockFile.createInputStream())) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
Streams.pipeAll(in, out);
return out.toByteArray();
}
}
示例12: getLockerEncryptedDataFile
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
@GET
@Path("{pgpKeyId}/{lockerContentName}/{version}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getLockerEncryptedDataFile(@PathParam("version") final String version) {
assertNotNull(version, "version");
assertNotNull(pgpKeyId, "pgpKeyId");
assertNotNull(lockerContentName, "lockerContentName");
final File file = createFile(lockerDir, pgpKeyId.toString(), lockerContentName, version.toString() + DATA_FILE_SUFFIX);
if (! file.exists())
return Response.status(Status.NOT_FOUND).build();
final StreamingOutput result = new StreamingOutput() {
@Override
public void write(final OutputStream out) throws IOException, WebApplicationException {
final File deletedFileToDeleteAgain;
try (final LockFile lockFile = LockFileFactory.getInstance().acquire(file, 30000);) {
try (final InputStream in = castStream(lockFile.createInputStream())) {
Streams.pipeAll(in, out);
out.flush();
}
final File f = lockFile.getFile();
deletedFileToDeleteAgain = f.length() == 0 ? f : null;
}
// In case the file was deleted between the check at the beginning of this method and this StreamingOutput's activity,
// we delete it again. We assume that it was deleted, if it is empty, because we now that all files we put into the
// locker are never empty - actually they are LockerEncryptedDataFile instances that must have header + signature.
if (deletedFileToDeleteAgain != null)
deletedFileToDeleteAgain.delete();
}
};
return Response.ok(result).build();
}
示例13: doInBackground
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
@Override
protected String doInBackground(Object... params) {
try {
if (SshTools.keyPairExists((File) params[0])) {
InetAddress address = InetAddress.getByName((String) params[1]);
int port = (Integer) params[2];
Socket client = new Socket(address, port);
OutputStream outToServer = client.getOutputStream();
DataOutputStream out = new DataOutputStream(outToServer);
FileInputStream in = new FileInputStream(new File((File) params[0], "id_rsa.pub"));
Streams.pipeAll(in, out);
out.flush();
out.close();
client.close();
} else {
throw new NoSshKeysException();
}
} catch (Exception e) {
this.exception = e;
}
return null;
}
示例14: parse
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
/**
* Parse a {@link HeartbeatMessage} from an {@link InputStream}.
*
* @param input
* the {@link InputStream} to parse from.
* @return a {@link HeartbeatMessage} object.
* @throws IOException
*/
public static HeartbeatMessage parse(InputStream input) throws IOException
{
short type = TlsUtils.readUint8(input);
if (!HeartbeatMessageType.isValid(type))
{
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
int payload_length = TlsUtils.readUint16(input);
PayloadBuffer buf = new PayloadBuffer();
Streams.pipeAll(input, buf);
byte[] payload = buf.toTruncatedByteArray(payload_length);
if (payload == null)
{
/*
* RFC 6520 4. If the payload_length of a received HeartbeatMessage is too large, the
* received HeartbeatMessage MUST be discarded silently.
*/
return null;
}
int padding_length = buf.size() - payload.length;
return new HeartbeatMessage(type, payload, padding_length);
}
示例15: decrypt
import org.bouncycastle.util.io.Streams; //导入方法依赖的package包/类
public static byte[] decrypt(
final byte[] data,
final InputStream privateKey,
final String passphrase)
throws CryptographyException {
final ByteArrayOutputStream out;
try {
final PGPLiteralData message = asLiteral(data, privateKey, passphrase);
out = new ByteArrayOutputStream();
Streams.pipeAll(message.getInputStream(), out);
} catch (IOException | PGPException e) {
throw new CryptographyException("Failed to decrypt.", e);
}
return out.toByteArray();
}