本文整理汇总了Java中org.bouncycastle.bcpg.CompressionAlgorithmTags.UNCOMPRESSED属性的典型用法代码示例。如果您正苦于以下问题:Java CompressionAlgorithmTags.UNCOMPRESSED属性的具体用法?Java CompressionAlgorithmTags.UNCOMPRESSED怎么用?Java CompressionAlgorithmTags.UNCOMPRESSED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.bouncycastle.bcpg.CompressionAlgorithmTags
的用法示例。
在下文中一共展示了CompressionAlgorithmTags.UNCOMPRESSED属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PGPCompressedDataGenerator
public PGPCompressedDataGenerator(
int algorithm,
int compression)
{
switch (algorithm)
{
case CompressionAlgorithmTags.UNCOMPRESSED:
case CompressionAlgorithmTags.ZIP:
case CompressionAlgorithmTags.ZLIB:
case CompressionAlgorithmTags.BZIP2:
break;
default:
throw new IllegalArgumentException("unknown compression algorithm");
}
if (compression != Deflater.DEFAULT_COMPRESSION)
{
if ((compression < Deflater.NO_COMPRESSION) || (compression > Deflater.BEST_COMPRESSION))
{
throw new IllegalArgumentException("unknown compression level: " + compression);
}
}
this.algorithm = algorithm;
this.compression = compression;
}
示例2: doOpen
private void doOpen() throws IOException
{
pkOut.write(algorithm);
switch (algorithm)
{
case CompressionAlgorithmTags.UNCOMPRESSED:
dOut = pkOut;
break;
case CompressionAlgorithmTags.ZIP:
dOut = new SafeDeflaterOutputStream(pkOut, compression, true);
break;
case CompressionAlgorithmTags.ZLIB:
dOut = new SafeDeflaterOutputStream(pkOut, compression, false);
break;
case CompressionAlgorithmTags.BZIP2:
dOut = new SafeCBZip2OutputStream(pkOut);
break;
default:
// Constructor should guard against this possibility
throw new IllegalStateException();
}
}
示例3: encrypt
public static byte[] encrypt(
final byte[] secret,
final PGPPublicKey... keys)
throws CryptographyException {
final ByteArrayOutputStream out;
try (ByteArrayInputStream in = new ByteArrayInputStream(secret);
ByteArrayOutputStream bOut = new ByteArrayOutputStream()) {
final PGPLiteralDataGenerator literal = new PGPLiteralDataGenerator();
final PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(CompressionAlgorithmTags.UNCOMPRESSED);
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(PGPEncryptedData.CAST5)
.setWithIntegrityPacket(true)
.setSecureRandom(new SecureRandom())
.setProvider(PROVIDER));
for (final PGPPublicKey key : keys) {
generator.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(key).setProvider(PROVIDER));
}
out = new ByteArrayOutputStream();
final ArmoredOutputStream armor = new ArmoredOutputStream(out);
final OutputStream cOut = generator.open(armor, bytes.length);
cOut.write(bytes);
cOut.close();
armor.close();
} catch (IOException | PGPException e) {
throw new CryptographyException("Failed to encrypt.", e);
}
return out.toByteArray();
}