本文整理汇总了Java中org.spongycastle.openpgp.PGPUtil类的典型用法代码示例。如果您正苦于以下问题:Java PGPUtil类的具体用法?Java PGPUtil怎么用?Java PGPUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PGPUtil类属于org.spongycastle.openpgp包,在下文中一共展示了PGPUtil类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: PGPPubkeyEncryptionUtil
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
public PGPPubkeyEncryptionUtil(String pubkeyBlock){
InputStream in = new ByteArrayInputStream(pubkeyBlock.getBytes());
publicKey = null;
try {
in = PGPUtil.getDecoderStream(in);
JcaPGPPublicKeyRingCollection pgpPub = new JcaPGPPublicKeyRingCollection(in);
in.close();
Iterator<PGPPublicKeyRing> rIt = pgpPub.getKeyRings();
while (publicKey == null && rIt.hasNext()) {
PGPPublicKeyRing keyRing = rIt.next();
Iterator<PGPPublicKey> kIt = keyRing.getPublicKeys();
while (publicKey == null && kIt.hasNext()) {
PGPPublicKey k = kIt.next();
if (k.isEncryptionKey()) {
publicKey = k;
}
}
}
} catch (Exception e){
Log.e(LOGCATTAG, e.toString());
}
}
开发者ID:TpmKranz,项目名称:SMS-Forward,代码行数:23,代码来源:PGPPubkeyEncryptionUtil.java
示例2: readPublicKeyFromCol
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
public static PGPPublicKey readPublicKeyFromCol(InputStream in) throws IOException, PGPException {
in = PGPUtil.getDecoderStream(in);
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(in, new BcKeyFingerprintCalculator());
PGPPublicKey key = null;
Iterator<PGPPublicKeyRing> keyRings = pgpPub.getKeyRings();
while (key == null && keyRings.hasNext()) {
PGPPublicKeyRing keyRing = keyRings.next();
Iterator<PGPPublicKey> keys = keyRing.getPublicKeys();
while (keys.hasNext()) {
PGPPublicKey k = keys.next();
if (k.isEncryptionKey()) {
key = k;
break;
}
}
}
if (key == null)
throw new PGPException("Can't find a valid encryption key in key ring.");
return key;
}
开发者ID:PassableShots,项目名称:PassableShots,代码行数:22,代码来源:EncryptionSystem.java
示例3: extractPublicKeyFromBytes
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static PGPPublicKey extractPublicKeyFromBytes(byte[] keyBlock) throws IOException, PGPException {
PGPPublicKeyRingCollection keyringCol = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(new ByteArrayInputStream(Base64.decode(keyBlock, Base64.DEFAULT))));
PGPPublicKey key = null;
Iterator<PGPPublicKeyRing> rIt = keyringCol.getKeyRings();
while(key == null && rIt.hasNext()) {
PGPPublicKeyRing keyring = (PGPPublicKeyRing) rIt.next();
Iterator<PGPPublicKey> kIt = keyring.getPublicKeys();
while(key == null && kIt.hasNext()) {
PGPPublicKey k = (PGPPublicKey) kIt.next();
if(k.isEncryptionKey())
key = k;
}
}
if(key == null) {
throw new IllegalArgumentException("there isn't an encryption key here.");
}
return key;
}
开发者ID:guardianproject,项目名称:CameraV,代码行数:22,代码来源:KeyUtility.java
示例4: compressFile
import org.spongycastle.openpgp.PGPUtil; //导入依赖的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
示例5: readPublicKey
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
/**
* A simple routine that opens a key ring file and loads the first available key
* suitable for encryption.
*
* @param input data stream containing the public key data
* @return the first public key found.
* @throws IOException
* @throws PGPException
*/
static PGPPublicKey readPublicKey(InputStream input) throws IOException, PGPException
{
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(
PGPUtil.getDecoderStream(input), new JcaKeyFingerprintCalculator());
//
// we just loop through the collection till we find a key suitable for encryption, in the real
// world you would probably want to be a bit smarter about this.
//
Iterator keyRingIter = pgpPub.getKeyRings();
while (keyRingIter.hasNext())
{
PGPPublicKeyRing keyRing = (PGPPublicKeyRing)keyRingIter.next();
Iterator keyIter = keyRing.getPublicKeys();
while (keyIter.hasNext())
{
PGPPublicKey key = (PGPPublicKey)keyIter.next();
if (key.isEncryptionKey())
{
return key;
}
}
}
throw new IllegalArgumentException("Can't find encryption key in key ring.");
}
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:39,代码来源:MyPGPUtil.java
示例6: readSecretKey
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
/**
* A simple routine that opens a key ring file and loads the first available key
* suitable for signature generation.
*
* @param input stream to read the secret key ring collection from.
* @return a secret key.
* @throws IOException on a problem with using the input stream.
* @throws PGPException if there is an issue parsing the input stream.
*/
public static PGPSecretKey readSecretKey(InputStream input) throws IOException, PGPException
{
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
PGPUtil.getDecoderStream(input), new JcaKeyFingerprintCalculator());
//
// we just loop through the collection till we find a key suitable for encryption, in the real
// world you would probably want to be a bit smarter about this.
//
Iterator keyRingIter = pgpSec.getKeyRings();
while (keyRingIter.hasNext())
{
PGPSecretKeyRing keyRing = (PGPSecretKeyRing)keyRingIter.next();
Iterator keyIter = keyRing.getSecretKeys();
while (keyIter.hasNext())
{
PGPSecretKey key = (PGPSecretKey)keyIter.next();
if (key.isSigningKey())
{
return key;
}
}
}
throw new IllegalArgumentException("Can't find signing key in key ring.");
}
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:39,代码来源:MyPGPUtil.java
示例7: getPublicKey
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
@Override
public PGPPublicKey getPublicKey(File file) throws Exception {
InputStream input=new FileInputStream(file);
JcaPGPPublicKeyRingCollection pgpPub = new JcaPGPPublicKeyRingCollection(PGPUtil.getDecoderStream(input));
PGPPublicKey pubKey = null;
@SuppressWarnings("unchecked")
Iterator<PGPPublicKeyRing> keyRingIterator = pgpPub.getKeyRings();
while (keyRingIterator.hasNext() && pubKey == null) {
PGPPublicKeyRing keyRing = keyRingIterator.next();
@SuppressWarnings("unchecked")
Iterator<PGPPublicKey> keyIterator = keyRing.getPublicKeys();
while (keyIterator.hasNext()) {
PGPPublicKey key = keyIterator.next();
if (key.isEncryptionKey()) {
pubKey = key;
break;
}
}
}
if(pubKey != null) {
return pubKey;
}
else {
throw new IllegalArgumentException("Can't find encryption key in key ring.");
}
}
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:31,代码来源:KeyManagement.java
示例8: crossCertify
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
/** Generates a cross-certification for a subkey. */
private static PGPSignature crossCertify(PGPKeyPair signer, PGPPublicKey key) throws PGPException {
PGPSignatureGenerator sGen = new PGPSignatureGenerator(
new JcaPGPContentSignerBuilder(signer.getPublicKey().getAlgorithm(),
PGPUtil.SHA256).setProvider(PROVIDER));
sGen.init(PGPSignature.PRIMARYKEY_BINDING, signer.getPrivateKey());
return sGen.generateCertification(key);
}
开发者ID:kontalk,项目名称:androidclient,代码行数:9,代码来源:PGP.java
示例9: revokeKey
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
/** Revokes the given key. */
public static PGPPublicKey revokeKey(PGPKeyPair secret)
throws PGPException, IOException, SignatureException {
PGPPrivateKey pgpPrivKey = secret.getPrivateKey();
PGPPublicKey pgpPubKey = secret.getPublicKey();
PGPSignatureGenerator sGen = new PGPSignatureGenerator(
new JcaPGPContentSignerBuilder(secret.getPublicKey().getAlgorithm(),
PGPUtil.SHA256).setProvider(PROVIDER));
sGen.init(PGPSignature.KEY_REVOCATION, pgpPrivKey);
return PGPPublicKey.addCertification(pgpPubKey, sGen.generateCertification(pgpPubKey));
}
开发者ID:kontalk,项目名称:androidclient,代码行数:16,代码来源:PGP.java
示例10: signPublicKey
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
/** Signs a public key with the given secret key. */
public static PGPPublicKey signPublicKey(PGPKeyPair secret, PGPPublicKey keyToBeSigned, String id, int certification)
throws PGPException, IOException, SignatureException {
PGPPrivateKey pgpPrivKey = secret.getPrivateKey();
PGPSignatureGenerator sGen = new PGPSignatureGenerator(
new JcaPGPContentSignerBuilder(secret.getPublicKey().getAlgorithm(),
PGPUtil.SHA1).setProvider(PROVIDER));
sGen.init(certification, pgpPrivKey);
return PGPPublicKey.addCertification(keyToBeSigned, id, sGen.generateCertification(id, keyToBeSigned));
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:15,代码来源:PGP.java
示例11: signUserAttributes
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
/** Signs and add the given user attributes to the given public key. */
public static PGPPublicKey signUserAttributes(PGPKeyPair secret, PGPPublicKey keyToBeSigned, PGPUserAttributeSubpacketVector attributes, int certification)
throws PGPException, SignatureException {
PGPPrivateKey pgpPrivKey = secret.getPrivateKey();
PGPSignatureGenerator sGen = new PGPSignatureGenerator(
new JcaPGPContentSignerBuilder(secret.getPublicKey().getAlgorithm(),
PGPUtil.SHA1).setProvider(PROVIDER));
sGen.init(certification, pgpPrivKey);
return PGPPublicKey.addCertification(keyToBeSigned, attributes,
sGen.generateCertification(attributes, keyToBeSigned));
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:16,代码来源:PGP.java
示例12: revokeKey
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
/** Revokes the given key. */
public static PGPPublicKey revokeKey(PGPKeyPair secret)
throws PGPException, IOException, SignatureException {
PGPPrivateKey pgpPrivKey = secret.getPrivateKey();
PGPPublicKey pgpPubKey = secret.getPublicKey();
PGPSignatureGenerator sGen = new PGPSignatureGenerator(
new JcaPGPContentSignerBuilder(secret.getPublicKey().getAlgorithm(),
PGPUtil.SHA1).setProvider(PROVIDER));
sGen.init(PGPSignature.KEY_REVOCATION, pgpPrivKey);
return PGPPublicKey.addCertification(pgpPubKey, sGen.generateCertification(pgpPubKey));
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:16,代码来源:PGP.java
示例13: compressFile
import org.spongycastle.openpgp.PGPUtil; //导入依赖的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
示例14: readPublicKey
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
/**
* A simple routine that opens a key ring file and loads the first available key
* suitable for encryption.
*
* @param input
* @return
* @throws IOException
* @throws PGPException
*/
@SuppressWarnings("rawtypes")
static PGPPublicKey readPublicKey(InputStream input) throws IOException, PGPException
{
PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(
PGPUtil.getDecoderStream(input));
//
// we just loop through the collection till we find a key suitable for encryption, in the real
// world you would probably want to be a bit smarter about this.
//
Iterator keyRingIter = pgpPub.getKeyRings();
while (keyRingIter.hasNext())
{
PGPPublicKeyRing keyRing = (PGPPublicKeyRing)keyRingIter.next();
Iterator keyIter = keyRing.getPublicKeys();
while (keyIter.hasNext())
{
PGPPublicKey key = (PGPPublicKey)keyIter.next();
if (key.isEncryptionKey())
{
return key;
}
}
}
throw new IllegalArgumentException("Can't find encryption key in key ring.");
}
开发者ID:snuk182,项目名称:aceim,代码行数:40,代码来源:EncryptionUtils.java
示例15: readSecretKey
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
/**
* A simple routine that opens a key ring file and loads the first available key
* suitable for signature generation.
*
* @param input stream to read the secret key ring collection from.
* @return a secret key.
* @throws IOException on a problem with using the input stream.
* @throws PGPException if there is an issue parsing the input stream.
*/
@SuppressWarnings("rawtypes")
public static PGPSecretKey readSecretKey(InputStream input) throws IOException, PGPException
{
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(
PGPUtil.getDecoderStream(input));
//
// we just loop through the collection till we find a key suitable for encryption, in the real
// world you would probably want to be a bit smarter about this.
//
Iterator keyRingIter = pgpSec.getKeyRings();
while (keyRingIter.hasNext())
{
PGPSecretKeyRing keyRing = (PGPSecretKeyRing)keyRingIter.next();
Iterator keyIter = keyRing.getSecretKeys();
while (keyIter.hasNext())
{
PGPSecretKey key = (PGPSecretKey)keyIter.next();
if (key.isSigningKey())
{
return key;
}
}
}
throw new IllegalArgumentException("Can't find signing key in key ring.");
}
开发者ID:snuk182,项目名称:aceim,代码行数:40,代码来源:EncryptionUtils.java
示例16: sign
import org.spongycastle.openpgp.PGPUtil; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private static String sign(String stanza, String keyPath, char[] pass) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, PGPException, SignatureException {
if (stanza == null) {
stanza = "";
}
PGPSecretKey pgpSecKey = EncryptionUtils.readSecretKey(keyPath);
PGPPrivateKey pgpPrivKey = pgpSecKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("SC").build(pass));
PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSecKey.getPublicKey().getAlgorithm(), PGPUtil.SHA1).setProvider("SC"));
PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
sGen.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey);
Iterator it = pgpSecKey.getPublicKey().getUserIDs();
if (it.hasNext()) {
spGen.setSignerUserID(false, (String) it.next());
sGen.setHashedSubpackets(spGen.generate());
}
InputStream fIn = new BufferedInputStream(new ByteArrayInputStream(stanza.getBytes()));
ByteArrayOutputStream out = new ByteArrayOutputStream();
ArmoredOutputStream aOut = new ArmoredOutputStream(out);
aOut.beginClearText(PGPUtil.SHA1);
//
// note the last \n/\r/\r\n in the file is ignored
//
ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
int lookAhead = readInputLine(lineOut, fIn);
processLine(aOut, sGen, lineOut.toByteArray());
if (lookAhead != -1) {
do {
lookAhead = readInputLine(lineOut, lookAhead, fIn);
sGen.update((byte) '\r');
sGen.update((byte) '\n');
processLine(aOut, sGen, lineOut.toByteArray());
} while (lookAhead != -1);
}
fIn.close();
aOut.endClearText();
BCPGOutputStream bOut = new BCPGOutputStream(aOut);
sGen.generate().encode(bOut);
aOut.close();
String signed = new String(out.toByteArray());
bOut.close();
return EncryptedDataProvider.removeHeaderFooter(signed);
}
开发者ID:snuk182,项目名称:aceim,代码行数:62,代码来源:SignedPresence.java
示例17: applySignature
import org.spongycastle.openpgp.PGPUtil; //导入依赖的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
注:本文中的org.spongycastle.openpgp.PGPUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论