本文整理汇总了Java中org.spongycastle.openpgp.PGPSignature类的典型用法代码示例。如果您正苦于以下问题:Java PGPSignature类的具体用法?Java PGPSignature怎么用?Java PGPSignature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PGPSignature类属于org.spongycastle.openpgp包,在下文中一共展示了PGPSignature类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: generateKeyRingGenerator
import org.spongycastle.openpgp.PGPSignature; //导入依赖的package包/类
public final static PGPKeyRingGenerator generateKeyRingGenerator (String keyId, char[] pass) throws PGPException{
RSAKeyPairGenerator kpg = new RSAKeyPairGenerator();
kpg.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001), new SecureRandom(), 4096, 12));
PGPKeyPair rsakp_sign = new BcPGPKeyPair(PGPPublicKey.RSA_SIGN, kpg.generateKeyPair(), new Date());
PGPKeyPair rsakp_enc = new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT, kpg.generateKeyPair(), new Date());
PGPSignatureSubpacketGenerator signhashgen = new PGPSignatureSubpacketGenerator();
signhashgen.setKeyFlags(false, KeyFlags.SIGN_DATA|KeyFlags.CERTIFY_OTHER|KeyFlags.SHARED);
signhashgen.setPreferredSymmetricAlgorithms(false, new int[]{SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192, SymmetricKeyAlgorithmTags.AES_128});
signhashgen.setPreferredHashAlgorithms(false, new int[]{HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA1, HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512, HashAlgorithmTags.SHA224});
signhashgen.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION);
PGPSignatureSubpacketGenerator enchashgen = new PGPSignatureSubpacketGenerator();
enchashgen.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);
PGPDigestCalculator sha1Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);
PGPDigestCalculator sha256Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA256);
PBESecretKeyEncryptor pske = (new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha256Calc, 0xc0)).build(pass);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator (PGPSignature.POSITIVE_CERTIFICATION, rsakp_sign,
keyId, sha1Calc, signhashgen.generate(), null, new BcPGPContentSignerBuilder(rsakp_sign.getPublicKey().getAlgorithm(),
HashAlgorithmTags.SHA1), pske);
keyRingGen.addSubKey(rsakp_enc, enchashgen.generate(), null);
return keyRingGen;
}
开发者ID:guardianproject,项目名称:proofmode,代码行数:22,代码来源:PgpUtils.java
示例2: store
import org.spongycastle.openpgp.PGPSignature; //导入依赖的package包/类
/** Creates public and secret keyring for a given keypair. */
public static PGPKeyPairRing store(PGPDecryptedKeyPairRing pair,
String id,
String passphrase)
throws PGPException {
PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, pair.signKey,
id, sha1Calc, null, null,
new JcaPGPContentSignerBuilder(pair.signKey.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1),
new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha1Calc)
.setProvider(PROVIDER).build(passphrase.toCharArray()));
keyRingGen.addSubKey(pair.encryptKey);
PGPSecretKeyRing secRing = keyRingGen.generateSecretKeyRing();
PGPPublicKeyRing pubRing = keyRingGen.generatePublicKeyRing();
return new PGPKeyPairRing(pubRing, secRing);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:21,代码来源:PGP.java
示例3: crossCertify
import org.spongycastle.openpgp.PGPSignature; //导入依赖的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
示例4: revokeKey
import org.spongycastle.openpgp.PGPSignature; //导入依赖的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
示例5: getKeyFlags
import org.spongycastle.openpgp.PGPSignature; //导入依赖的package包/类
public static int getKeyFlags(PGPPublicKey key) {
@SuppressWarnings("unchecked")
Iterator<PGPSignature> sigs = key.getSignatures();
while (sigs.hasNext()) {
PGPSignature sig = sigs.next();
if (sig != null) {
PGPSignatureSubpacketVector subpackets = sig.getHashedSubPackets();
if (subpackets != null) {
return subpackets.getKeyFlags();
}
}
}
return 0;
}
开发者ID:kontalk,项目名称:androidclient,代码行数:15,代码来源:PGP.java
示例6: revokeKey
import org.spongycastle.openpgp.PGPSignature; //导入依赖的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
示例7: generateKey
import org.spongycastle.openpgp.PGPSignature; //导入依赖的package包/类
@Override
public PGPKeyRingGenerator generateKey(String email, char[] password) throws Exception {
RSAKeyPairGenerator rsaKeyPairGenerator=new RSAKeyPairGenerator();
rsaKeyPairGenerator.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001),new SecureRandom(),2048,12));
PGPKeyPair keyPair=new BcPGPKeyPair(PGPPublicKey.RSA_SIGN,rsaKeyPairGenerator.generateKeyPair(),new Date());
PGPKeyPair enKeyPair=new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT,rsaKeyPairGenerator.generateKeyPair(),new Date());
// Add a self-signature on the id
PGPSignatureSubpacketGenerator signhashgen =
new PGPSignatureSubpacketGenerator();
// Add signed metadata on the signature.
// 1) Declare its purpose
signhashgen.setKeyFlags
(false, KeyFlags.SIGN_DATA|KeyFlags.CERTIFY_OTHER);
// 2) Set preferences for secondary crypto algorithms to use
// when sending messages to this key.
signhashgen.setPreferredSymmetricAlgorithms
(false, new int[] {
SymmetricKeyAlgorithmTags.AES_256,
SymmetricKeyAlgorithmTags.AES_192,
SymmetricKeyAlgorithmTags.AES_128
});
signhashgen.setPreferredHashAlgorithms
(false, new int[] {
HashAlgorithmTags.SHA256,
HashAlgorithmTags.SHA1,
HashAlgorithmTags.SHA384,
HashAlgorithmTags.SHA512,
HashAlgorithmTags.SHA224,
});
// 3) Request senders add additional checksums to the
// message (useful when verifying unsigned messages.)
signhashgen.setFeature
(false, Features.FEATURE_MODIFICATION_DETECTION);
// Create a signature on the encryption subkey.
PGPSignatureSubpacketGenerator enchashgen =
new PGPSignatureSubpacketGenerator();
// Add metadata to declare its purpose
enchashgen.setKeyFlags
(false, KeyFlags.ENCRYPT_COMMS|KeyFlags.ENCRYPT_STORAGE);
// Objects used to encrypt the secret key.
PGPDigestCalculator sha1Calc =
new BcPGPDigestCalculatorProvider()
.get(HashAlgorithmTags.SHA1);
PGPDigestCalculator sha256Calc =
new BcPGPDigestCalculatorProvider()
.get(HashAlgorithmTags.SHA256);
PBESecretKeyEncryptor pske =
(new BcPBESecretKeyEncryptorBuilder
(PGPEncryptedData.AES_256, sha256Calc, 0xc0))
.build(password);
// Finally, create the keyring itself. The constructor
// takes parameters that allow it to generate the self
// signature.
PGPKeyRingGenerator keyRingGen =
new PGPKeyRingGenerator
(PGPSignature.POSITIVE_CERTIFICATION, keyPair,
email, sha1Calc, signhashgen.generate(), null,
new BcPGPContentSignerBuilder
(keyPair.getPublicKey().getAlgorithm(),
HashAlgorithmTags.SHA1),
pske);
// Add our encryption subkey, together with its signature.
keyRingGen.addSubKey
(enKeyPair, enchashgen.generate(), null);
return keyRingGen;
}
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:75,代码来源:KeyManagement.java
示例8: encryptData
import org.spongycastle.openpgp.PGPSignature; //导入依赖的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
示例9: signPublicKey
import org.spongycastle.openpgp.PGPSignature; //导入依赖的package包/类
/** Signs a public key with the given secret key. */
public static PGPPublicKey signPublicKey(PGPKeyPair secret, PGPPublicKey keyToBeSigned, String id)
throws PGPException, IOException, SignatureException {
return signPublicKey(secret, keyToBeSigned, id, PGPSignature.CASUAL_CERTIFICATION);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:7,代码来源:PGP.java
示例10: signUserAttributes
import org.spongycastle.openpgp.PGPSignature; //导入依赖的package包/类
/** Signs and add the given user attributes to the given public key. */
public static PGPPublicKey signUserAttributes(PGPKeyPair secret, PGPPublicKey keyToBeSigned, PGPUserAttributeSubpacketVector attributes)
throws PGPException, SignatureException {
return signUserAttributes(secret, keyToBeSigned, attributes, PGPSignature.POSITIVE_CERTIFICATION);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:7,代码来源:PGP.java
示例11: revokeUserAttributes
import org.spongycastle.openpgp.PGPSignature; //导入依赖的package包/类
public static PGPPublicKey revokeUserAttributes(PGPKeyPair secret, PGPPublicKey keyToBeSigned, PGPUserAttributeSubpacketVector attributes)
throws SignatureException, PGPException {
return PGP.signUserAttributes(secret, keyToBeSigned, attributes,
PGPSignature.CERTIFICATION_REVOCATION);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:7,代码来源:PGP.java
示例12: testOpenPgp
import org.spongycastle.openpgp.PGPSignature; //导入依赖的package包/类
/**
* https://github.com/wesabe/grendel/blob/master/src/test/java/com/wesabe/
* grendel/openpgp/tests/KeySetGeneratorTest.java
*
* @throws PGPException
*/
@Test
public void testOpenPgp() throws PGPException {
String id = "[email protected]";
String pass = "hello";
int s2kcount = 0xc1;
// http://bouncycastle-pgp-cookbook.blogspot.tw/2013/01/generating-rsa-keys.html
RSAKeyPairGenerator kpg = new RSAKeyPairGenerator();
kpg.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001),
new SecureRandom(), 2048, 12));
BcPGPKeyPair bkpSign = new BcPGPKeyPair(PGPPublicKey.RSA_SIGN,
kpg.generateKeyPair(), new Date());
assertNotNull(bkpSign);
BcPGPKeyPair bkpEncrypt = new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT,
kpg.generateKeyPair(), new Date());
assertNotNull(bkpEncrypt);
PGPSignatureSubpacketGenerator signhashgen = new PGPSignatureSubpacketGenerator();
signhashgen.setKeyFlags(false, KeyFlags.SIGN_DATA
| KeyFlags.CERTIFY_OTHER);
signhashgen.setPreferredSymmetricAlgorithms(false, new int[] {
SymmetricKeyAlgorithmTags.AES_256,
SymmetricKeyAlgorithmTags.AES_192,
SymmetricKeyAlgorithmTags.AES_128 });
signhashgen.setPreferredHashAlgorithms(false, new int[] {
HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA1,
HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512,
HashAlgorithmTags.SHA224, });
signhashgen.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION);
PGPSignatureSubpacketGenerator enchashgen = new PGPSignatureSubpacketGenerator();
enchashgen.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS
| KeyFlags.ENCRYPT_STORAGE);
PGPDigestCalculator sha1Calc = new BcPGPDigestCalculatorProvider()
.get(HashAlgorithmTags.SHA1);
PGPDigestCalculator sha256Calc = new BcPGPDigestCalculatorProvider()
.get(HashAlgorithmTags.SHA256);
// bcpg 1.48 exposes this API that includes s2kcount. Earlier
// versions use a default of 0x60.
PBESecretKeyEncryptor pske = (new BcPBESecretKeyEncryptorBuilder(
PGPEncryptedData.AES_256, sha256Calc))
.build(pass.toCharArray());
// Finally, create the keyring itself. The constructor
// takes parameters that allow it to generate the self
// signature.
PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(
PGPSignature.POSITIVE_CERTIFICATION, bkpSign, id, sha1Calc,
signhashgen.generate(), null, new BcPGPContentSignerBuilder(
bkpSign.getPublicKey().getAlgorithm(),
HashAlgorithmTags.SHA1), pske);
// Add our encryption subkey, together with its signature.
keyRingGen.addSubKey(bkpEncrypt, enchashgen.generate(), null);
assertNotNull(keyRingGen);
}
开发者ID:y12studio,项目名称:bkbc-tools,代码行数:70,代码来源:MainPrivKeyShareTest.java
示例13: sign
import org.spongycastle.openpgp.PGPSignature; //导入依赖的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
示例14: applySignature
import org.spongycastle.openpgp.PGPSignature; //导入依赖的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.PGPSignature类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论