• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PGPCompressedDataGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: encrypt

import org.spongycastle.openpgp.PGPCompressedDataGenerator; //导入依赖的package包/类
public String encrypt(String plainText) throws NoSuchAlgorithmException, IOException, PGPException {
    byte[] rawText = plainText.getBytes();
    //This needs, like, three metric fucktons of explanation and/or cleaning up
    ByteArrayOutputStream encOut = new ByteArrayOutputStream();
    OutputStream out = new ArmoredOutputStream(encOut);
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(PGPCompressedData.ZIP);
    OutputStream cos = comData.open(bOut);
    PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();
    OutputStream pOut = lData.open(cos, PGPLiteralData.BINARY, PGPLiteralData.CONSOLE, rawText.length, new Date());
    pOut.write(rawText);
    lData.close();
    comData.close();
    BcPGPDataEncryptorBuilder builder = new BcPGPDataEncryptorBuilder(PGPEncryptedData.AES_256);
    builder.setWithIntegrityPacket(true);
    builder.setSecureRandom(new SecureRandom());
    PGPEncryptedDataGenerator cpk = new PGPEncryptedDataGenerator(builder);
    cpk.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(publicKey));
    byte[] bytes = bOut.toByteArray();
    OutputStream cOut = cpk.open(out, bytes.length);
    cOut.write(bytes);
    cOut.close();
    out.close();
    return new String(encOut.toByteArray(), Charset.forName("UTF-8"));
}
 
开发者ID:TpmKranz,项目名称:SMS-Forward,代码行数:26,代码来源:PGPPubkeyEncryptionUtil.java


示例2: compressFile

import org.spongycastle.openpgp.PGPCompressedDataGenerator; //导入依赖的package包/类
static byte[] compressFile(String fileName, int algorithm) throws IOException
{
    ByteArrayOutputStream bOut          = new ByteArrayOutputStream();
    PGPCompressedDataGenerator comData  = new PGPCompressedDataGenerator(algorithm);
    PGPUtil.writeFileToLiteralData(comData.open(bOut), PGPLiteralData.BINARY,
            new File(fileName));
    comData.close();
    return bOut.toByteArray();
}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:10,代码来源:MyPGPUtil.java


示例3: encryptFile

import org.spongycastle.openpgp.PGPCompressedDataGenerator; //导入依赖的package包/类
public static boolean encryptFile(InputStream in, OutputStream out, File pubKeyFile,
                           boolean integrityCheck, Date fileDate,String filename){
    boolean status;
   try{
       PGPPublicKey encKey=MyPGPUtil.readPublicKey(new FileInputStream(pubKeyFile));
       Security.addProvider(new BouncyCastleProvider());

       PGPEncryptedDataGenerator cPk =
               new PGPEncryptedDataGenerator(
                       new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).
                               setWithIntegrityPacket(integrityCheck).
                               setSecureRandom(
                                       new SecureRandom()
                               )
               );

       cPk.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(encKey));

       OutputStream                cOut = cPk.open(out, new byte[1 << 16]);

       PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(
               PGPCompressedData.UNCOMPRESSED);

       PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();
       OutputStream pOut = lData.open(comData.open(cOut), PGPLiteralData.BINARY,filename ,fileDate, new byte[1 << 16]);
       PGPUtil.pipeDocumentFileContents(in,pOut, new byte[1 << 16].length);
       comData.close();

       cOut.close();
       Log.d(TAG,"file successfully encrypted");
       status=true;
   }catch (Exception ex){
       Log.d(TAG, "encryptFile: error in encrypting document file");
       ex.printStackTrace();
       status=false;
   }

    return status;
}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:40,代码来源:DocumentFileEncryption.java


示例4: encryptFile

import org.spongycastle.openpgp.PGPCompressedDataGenerator; //导入依赖的package包/类
@Override
public boolean encryptFile(File outputFile, File inputFile,
                         File pubKeyFile,Boolean integrityCheck
) throws Exception {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile));
    String fileName=inputFile.getPath();
    PGPPublicKey encKey=keyManagement.getPublicKey(pubKeyFile);
    Security.addProvider(new BouncyCastleProvider());

    PGPEncryptedDataGenerator cPk =
            new PGPEncryptedDataGenerator(
                    new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).
                            setWithIntegrityPacket(integrityCheck).
                            setSecureRandom(
                                    new SecureRandom()
                            )
            );

    cPk.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(encKey));

    OutputStream                cOut = cPk.open(out, new byte[1 << 16]);

    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(
            PGPCompressedData.UNCOMPRESSED);

    PGPUtil.writeFileToLiteralData(comData.open(cOut), PGPLiteralData.BINARY, new File(fileName), new byte[1 << 16]);

    comData.close();

    cOut.close();
    Log.d("encrypt","file successfully encrypted");
    return true;
}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:34,代码来源:EncryptionManagement.java


示例5: encrypt

import org.spongycastle.openpgp.PGPCompressedDataGenerator; //导入依赖的package包/类
public String encrypt(String msgText) throws IOException, PGPException {
    byte[] clearData = msgText.getBytes();
    PGPPublicKey encKey = getPublicKey(pkr);
    ByteArrayOutputStream encOut = new ByteArrayOutputStream();
    OutputStream out = new ArmoredOutputStream(encOut);
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(PGPCompressedDataGenerator.ZIP);
    OutputStream cos = comData.open(bOut);
    PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();
    OutputStream pOut = lData.open(cos, PGPLiteralData.BINARY, PGPLiteralData.CONSOLE, clearData.length, new Date());
    pOut.write(clearData);
    lData.close();
    comData.close();
    PGPEncryptedDataGenerator encGen =
            new PGPEncryptedDataGenerator(
                    new JcePGPDataEncryptorBuilder(PGPEncryptedData.AES_256).setWithIntegrityPacket(true).setSecureRandom(
                            new SecureRandom()).setProvider(PROVIDER));
    if (encKey != null) {
        encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(encKey).setProvider(PROVIDER));
        byte[] bytes = bOut.toByteArray();
        OutputStream cOut = encGen.open(out, bytes.length);
        cOut.write(bytes);
        cOut.close();
    }
    out.close();
    return new String(encOut.toByteArray());
}
 
开发者ID:guardianproject,项目名称:proofmode,代码行数:28,代码来源:PgpUtils.java


示例6: compressFile

import org.spongycastle.openpgp.PGPCompressedDataGenerator; //导入依赖的package包/类
static byte[] compressFile(String fileName, int algorithm) throws IOException
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(algorithm);
    PGPUtil.writeFileToLiteralData(comData.open(bOut), PGPLiteralData.BINARY,
        new File(fileName));
    comData.close();
    return bOut.toByteArray();
}
 
开发者ID:snuk182,项目名称:aceim,代码行数:10,代码来源:EncryptionUtils.java


示例7: encryptData

import org.spongycastle.openpgp.PGPCompressedDataGenerator; //导入依赖的package包/类
private byte[] encryptData(String mime, CharSequence data)
        throws PGPException, IOException, SignatureException {

    String from = mKey.getUserId(mServer.getNetwork());
    String[] to = new String[mRecipients.length];
    for (int i = 0; i < to.length; i++)
        to[i] = PGP.getUserId(PGP.getMasterKey(mRecipients[i]), mServer.getNetwork());

    // secure the message against the most basic attacks using Message/CPIM
    CPIMMessage cpim = new CPIMMessage(from, to, new Date(), mime, data);
    byte[] plainText = cpim.toByteArray();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayInputStream in = new ByteArrayInputStream(plainText);

    // setup data encryptor & generator
    BcPGPDataEncryptorBuilder encryptor = new BcPGPDataEncryptorBuilder(PGPEncryptedData.AES_192);
    encryptor.setWithIntegrityPacket(true);
    encryptor.setSecureRandom(new SecureRandom());

    // add public key recipients
    PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(encryptor);
    for (PGPPublicKeyRing rcpt : mRecipients)
        encGen.addMethod(new BcPublicKeyKeyEncryptionMethodGenerator(PGP.getEncryptionKey(rcpt)));

    OutputStream encryptedOut = encGen.open(out, new byte[BUFFER_SIZE]);

    // setup compressed data generator
    PGPCompressedDataGenerator compGen = new PGPCompressedDataGenerator(PGPCompressedData.ZIP);
    OutputStream compressedOut = compGen.open(encryptedOut, new byte[BUFFER_SIZE]);

    // setup signature generator
    PGPSignatureGenerator sigGen = new PGPSignatureGenerator
            (new BcPGPContentSignerBuilder(mKey.getSignKeyPair()
                .getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA256));
    sigGen.init(PGPSignature.BINARY_DOCUMENT, mKey.getSignKeyPair().getPrivateKey());

    PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
    spGen.setSignerUserID(false, mKey.getUserId(mServer.getNetwork()));
    sigGen.setUnhashedSubpackets(spGen.generate());

    sigGen.generateOnePassVersion(false)
        .encode(compressedOut);

    // Initialize literal data generator
    PGPLiteralDataGenerator literalGen = new PGPLiteralDataGenerator();
    OutputStream literalOut = literalGen.open(
        compressedOut,
        PGPLiteralData.BINARY,
        "",
        new Date(),
        new byte[BUFFER_SIZE]);

    // read the "in" stream, compress, encrypt and write to the "out" stream
    // this must be done if clear data is bigger than the buffer size
    // but there are other ways to optimize...
    byte[] buf = new byte[BUFFER_SIZE];
    int len;
    while ((len = in.read(buf)) > 0) {
        literalOut.write(buf, 0, len);
        sigGen.update(buf, 0, len);
    }

    in.close();
    literalGen.close();
    // Generate the signature, compress, encrypt and write to the "out" stream
    sigGen.generate().encode(compressedOut);
    compGen.close();
    encGen.close();

    return out.toByteArray();
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:73,代码来源:PGPCoder.java


示例8: applySignature

import org.spongycastle.openpgp.PGPCompressedDataGenerator; //导入依赖的package包/类
@SuppressWarnings({ "deprecation" })
public static byte[] applySignature(byte[] data, PGPSecretKey secretKey, PGPPublicKey publicKey, PGPPrivateKey privateKey) throws NoSuchAlgorithmException, PGPException, IOException, SignatureException {
	BouncyCastleProvider bc = new BouncyCastleProvider();
	Security.addProvider(bc);

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	
	OutputStream targetOut = new ArmoredOutputStream(baos);
	
	PGPSignatureGenerator sGen = new PGPSignatureGenerator(secretKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1, bc);
	sGen.initSign(PGPSignature.BINARY_DOCUMENT, privateKey);
	
	PGPCompressedDataGenerator cGen = new PGPCompressedDataGenerator(PGPCompressedDataGenerator.ZLIB);
	BCPGOutputStream bOut = new BCPGOutputStream(cGen.open(targetOut));
	
	sGen.update(data);
	
	sGen.generate().encode(bOut);
	
	cGen.close();
	bOut.close();
	targetOut.close();
	
	byte[] outdata = baos.toByteArray();
	return outdata;


}
 
开发者ID:guardianproject,项目名称:CameraV,代码行数:29,代码来源:KeyUtility.java


示例9: encrypt

import org.spongycastle.openpgp.PGPCompressedDataGenerator; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public final static void encrypt(InputStream is, OutputStream os, byte[] publicKey) throws NoSuchProviderException, PGPException, IOException {
	
	BouncyCastleProvider bc = new BouncyCastleProvider();
	int bufferSize = 1 << 16;
	
	Security.addProvider(bc);
	
	OutputStream aos = new ArmoredOutputStream(os);
	
	PGPEncryptedDataGenerator edg = new PGPEncryptedDataGenerator(PGPEncryptedData.AES_256, true, new SecureRandom(), bc);
	edg.addMethod(KeyUtility.extractPublicKeyFromBytes(publicKey));
	OutputStream encOs = edg.open(aos, new byte[bufferSize]);
	
	PGPCompressedDataGenerator cdg = new PGPCompressedDataGenerator(PGPCompressedData.ZIP);
	OutputStream compOs = cdg.open(encOs);
	
	PGPLiteralDataGenerator ldg = new PGPLiteralDataGenerator();
	OutputStream litOs = ldg.open(compOs, PGPLiteralData.BINARY, PGPLiteralData.CONSOLE, new Date(System.currentTimeMillis()), new byte[bufferSize]);
	
	byte[] buf = new byte[bufferSize];
	
	int len;
	while((len = is.read(buf)) > 0)
		litOs.write(buf, 0, len);
	
	litOs.flush();
	litOs.close();
	ldg.close();
	
	compOs.flush();
	compOs.close();
	cdg.close();
	
	encOs.flush();
	encOs.close();
	edg.close();
	
	aos.close();
	
	is.close();
		
}
 
开发者ID:guardianproject,项目名称:CameraV,代码行数:44,代码来源:EncryptionUtility.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JSONReader类代码示例发布时间:2022-05-23
下一篇:
Java BaseRobotRules类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap