本文整理汇总了Java中org.spongycastle.openpgp.PGPCompressedData类的典型用法代码示例。如果您正苦于以下问题:Java PGPCompressedData类的具体用法?Java PGPCompressedData怎么用?Java PGPCompressedData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PGPCompressedData类属于org.spongycastle.openpgp包,在下文中一共展示了PGPCompressedData类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: encrypt
import org.spongycastle.openpgp.PGPCompressedData; //导入依赖的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: encryptFile
import org.spongycastle.openpgp.PGPCompressedData; //导入依赖的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
示例3: encryptFile
import org.spongycastle.openpgp.PGPCompressedData; //导入依赖的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
示例4: encryptFile
import org.spongycastle.openpgp.PGPCompressedData; //导入依赖的package包/类
@Override
public boolean encryptFile(File inputFile, File outputFile, File keyFile, Boolean integrityCheck) throws Exception {
try
{
byte[] bytes = MyPGPUtil.compressFile(inputFile.getAbsolutePath(),PGPCompressedData.ZIP);
OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile));
Security.addProvider(new BouncyCastleProvider());
PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(
new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5).setWithIntegrityPacket(integrityCheck).setSecureRandom(new SecureRandom()));
PGPPublicKey key= MyPGPUtil.readPublicKey(new FileInputStream(keyFile));
encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(key).setProvider("BC"));
OutputStream cOut = encGen.open(out, bytes.length);
cOut.write(bytes);
cOut.close();
out.close();
// if i got here means encryption was successful
return true;
}
catch (PGPException e)
{
Log.i(TAG, "encryptFile: cannot encrypt file");
if (e.getUnderlyingException() != null)
{
e.getUnderlyingException().printStackTrace();
}
return false;
}
}
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:34,代码来源:EncryptionSmallFileProcessor.java
示例5: encryptData
import org.spongycastle.openpgp.PGPCompressedData; //导入依赖的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
示例6: encrypt
import org.spongycastle.openpgp.PGPCompressedData; //导入依赖的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.PGPCompressedData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论