本文整理汇总了Java中org.spongycastle.openpgp.PGPLiteralData类的典型用法代码示例。如果您正苦于以下问题:Java PGPLiteralData类的具体用法?Java PGPLiteralData怎么用?Java PGPLiteralData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PGPLiteralData类属于org.spongycastle.openpgp包,在下文中一共展示了PGPLiteralData类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: encrypt
import org.spongycastle.openpgp.PGPLiteralData; //导入依赖的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.PGPLiteralData; //导入依赖的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.PGPLiteralData; //导入依赖的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.PGPLiteralData; //导入依赖的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.PGPLiteralData; //导入依赖的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: encrypt
import org.spongycastle.openpgp.PGPLiteralData; //导入依赖的package包/类
public static byte[] encrypt(byte[] payload) throws IOException, PGPException {
ByteArrayOutputStream packetBaos = new ByteArrayOutputStream();
PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();
OutputStream packetOut = lData.open(packetBaos, PGPLiteralData.BINARY, "picture.jpeg", payload.length, new Date());
packetOut.write(payload);
packetOut.close();
byte[]packet =packetBaos.toByteArray();
PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(
new JcePGPDataEncryptorBuilder(PGPEncryptedData.CAST5)
.setWithIntegrityPacket(true)
.setSecureRandom(new SecureRandom())
.setProvider("SC"));
encGen.addMethod(new JcePublicKeyKeyEncryptionMethodGenerator(key).setProvider("SC"));
ByteArrayOutputStream resultBaos = new ByteArrayOutputStream();
OutputStream encOut = encGen.open(resultBaos, packet.length);
encOut.write(packet);
encOut.close();
byte[] result = resultBaos.toByteArray();
return result;
}
开发者ID:PassableShots,项目名称:PassableShots,代码行数:28,代码来源:EncryptionSystem.java
示例7: compressFile
import org.spongycastle.openpgp.PGPLiteralData; //导入依赖的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
示例8: compressFile
import org.spongycastle.openpgp.PGPLiteralData; //导入依赖的package包/类
static byte[] compressFile(byte[] data, int algorithm) throws IOException
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
/*PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(algorithm);
PGPUtil.writeFileToLiteralData(comData.open(bOut), PGPLiteralData.BINARY,
new File(fileName));*/
EncryptionUtils.writeToLiteralData(new ByteArrayInputStream(data), bOut, PGPLiteralData.BINARY, "");
byte[] bbytes = bOut.toByteArray();
bOut.close();
return bbytes;
}
开发者ID:snuk182,项目名称:aceim,代码行数:15,代码来源:EncryptedMessage.java
示例9: encryptData
import org.spongycastle.openpgp.PGPLiteralData; //导入依赖的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
示例10: encrypt
import org.spongycastle.openpgp.PGPLiteralData; //导入依赖的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.PGPLiteralData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论