本文整理汇总了Java中org.spongycastle.openpgp.PGPPublicKeyRing类的典型用法代码示例。如果您正苦于以下问题:Java PGPPublicKeyRing类的具体用法?Java PGPPublicKeyRing怎么用?Java PGPPublicKeyRing使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PGPPublicKeyRing类属于org.spongycastle.openpgp包,在下文中一共展示了PGPPublicKeyRing类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: PGPPubkeyEncryptionUtil
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的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.PGPPublicKeyRing; //导入依赖的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: getEncryptionKey
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
public static PGPPublicKey getEncryptionKey(PGPPublicKeyRing publicKeyring) {
@SuppressWarnings("unchecked")
Iterator<PGPPublicKey> iter = publicKeyring.getPublicKeys();
while (iter.hasNext()) {
PGPPublicKey pk = iter.next();
if (!pk.isMasterKey()) {
int keyFlags = getKeyFlags(pk);
if ((keyFlags & PGPKeyFlags.CAN_ENCRYPT_COMMS) == PGPKeyFlags.CAN_ENCRYPT_COMMS)
return pk;
}
}
// legacy key format support
return getLegacyEncryptionKey(publicKeyring);
}
开发者ID:kontalk,项目名称:androidclient,代码行数:17,代码来源:PGP.java
示例4: createCertificate
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
public static X509Certificate createCertificate(byte[] privateKeyData, byte[] publicKeyData, String passphrase)
throws PGPException, IOException, InvalidKeyException, IllegalStateException,
NoSuchAlgorithmException, SignatureException, CertificateException, NoSuchProviderException, OperatorCreationException {
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, sFingerprintCalculator);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, sFingerprintCalculator);
PGPDigestCalculatorProvider sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(sha1Calc)
.setProvider(PGP.PROVIDER)
.build(passphrase.toCharArray());
// secret key
PGPSecretKey secKey = secRing.getSecretKey();
return createCertificate(pubRing, secKey.extractPrivateKey(decryptor));
}
开发者ID:kontalk,项目名称:androidclient,代码行数:18,代码来源:X509Bridge.java
示例5: updateAccountManager
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
/** Stores the public keyring to the system {@link AccountManager}. */
public void updateAccountManager(Context context)
throws IOException, InvalidKeyException,
IllegalStateException, NoSuchAlgorithmException, SignatureException,
CertificateException, NoSuchProviderException, PGPException, OperatorCreationException {
AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
Account account = Authenticator.getDefaultAccount(am);
if (account != null) {
PGPPublicKeyRing pubRing = getPublicKeyRing();
// regenerate bridge certificate
byte[] bridgeCertData = X509Bridge.createCertificate(pubRing,
mPair.authKey.getPrivateKey()).getEncoded();
byte[] publicKeyData = pubRing.getEncoded();
am.setUserData(account, Authenticator.DATA_PUBLICKEY,
Base64.encodeToString(publicKeyData, Base64.NO_WRAP));
am.setUserData(account, Authenticator.DATA_BRIDGECERT,
Base64.encodeToString(bridgeCertData, Base64.NO_WRAP));
}
}
开发者ID:kontalk,项目名称:androidclient,代码行数:24,代码来源:PersonalKey.java
示例6: store
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的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
示例7: createCertificate
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
public static X509Certificate createCertificate(byte[] privateKeyData, byte[] publicKeyData, String passphrase, String subjectAltName)
throws PGPException, IOException, InvalidKeyException, IllegalStateException,
NoSuchAlgorithmException, SignatureException, CertificateException, NoSuchProviderException {
KeyFingerPrintCalculator fpr = new BcKeyFingerprintCalculator();
PGPSecretKeyRing secRing = new PGPSecretKeyRing(privateKeyData, fpr);
PGPPublicKeyRing pubRing = new PGPPublicKeyRing(publicKeyData, fpr);
PGPDigestCalculatorProvider sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build();
PBESecretKeyDecryptor decryptor = new JcePBESecretKeyDecryptorBuilder(sha1Calc)
.setProvider(PGP.PROVIDER)
.build(passphrase.toCharArray());
// secret key
PGPSecretKey secKey = secRing.getSecretKey();
return createCertificate(pubRing, secKey.extractPrivateKey(decryptor), subjectAltName);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:19,代码来源:X509Bridge.java
示例8: signPublicKey
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
/**
* Searches for the master (signing) key in the given public keyring and
* signs it with our master key.
* @return the same public keyring with the signed key. This is suitable to
* be imported directly into GnuPG.
* @see #signPublicKey(PGPPublicKey, String)
*/
@SuppressWarnings("unchecked")
public PGPPublicKeyRing signPublicKey(byte[] publicKeyring, String id)
throws PGPException, IOException, SignatureException {
PGPObjectFactory reader = new PGPObjectFactory(publicKeyring);
Object o = reader.nextObject();
while (o != null) {
if (o instanceof PGPPublicKeyRing) {
PGPPublicKeyRing pubRing = (PGPPublicKeyRing) o;
Iterator<PGPPublicKey> iter = pubRing.getPublicKeys();
while (iter.hasNext()) {
PGPPublicKey pk = iter.next();
if (pk.isMasterKey()) {
PGPPublicKey signed = signPublicKey(pk, id);
return PGPPublicKeyRing.insertPublicKey(pubRing, signed);
}
}
}
o = reader.nextObject();
}
throw new PGPException("invalid keyring data.");
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:31,代码来源:PersonalKey.java
示例9: updateAccountManager
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
/** Stores the public keyring to the system {@link AccountManager}. */
public void updateAccountManager(Context context)
throws IOException, CertificateEncodingException, InvalidKeyException,
IllegalStateException, NoSuchAlgorithmException, SignatureException,
CertificateException, NoSuchProviderException, PGPException {
AccountManager am = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
Account account = Authenticator.getDefaultAccount(am);
if (account != null) {
PGPPublicKeyRing pubRing = getPublicKeyRing();
// regenerate bridge certificate
byte[] bridgeCertData = X509Bridge.createCertificate(pubRing,
mPair.signKey.getPrivateKey(), null).getEncoded();
byte[] publicKeyData = pubRing.getEncoded();
am.setUserData(account, Authenticator.DATA_PUBLICKEY,
Base64.encodeToString(publicKeyData, Base64.NO_WRAP));
am.setUserData(account, Authenticator.DATA_BRIDGECERT,
Base64.encodeToString(bridgeCertData, Base64.NO_WRAP));
}
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:24,代码来源:PersonalKey.java
示例10: getEncryptCoder
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
/** Returns a {@link Coder} instance for encrypting data. */
public static Coder getEncryptCoder(Context context, EndpointServer server, PersonalKey key, String[] recipients) {
// get recipients public keys from users database
PGPPublicKey keys[] = new PGPPublicKey[recipients.length];
for (int i = 0; i < recipients.length; i++) {
String rcpt = StringUtils.parseName(recipients[i]);
PGPPublicKeyRing ring = getPublicKey(context, rcpt);
if (ring == null)
throw new IllegalArgumentException("public key not found for user " + rcpt);
keys[i] = PGP.getEncryptionKey(ring);
if (keys[i] == null)
throw new IllegalArgumentException("public key not found for user " + rcpt);
}
return new PGPCoder(server, key, keys);
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:19,代码来源:UsersProvider.java
示例11: getPublicKey
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
/** Retrieves the public key for a user. */
public static PGPPublicKeyRing getPublicKey(Context context, String userId) {
byte[] keydata = null;
ContentResolver res = context.getContentResolver();
Cursor c = res.query(Users.CONTENT_URI,
new String[] { Users.PUBLIC_KEY },
Users.HASH + "=?",
new String[] { userId },
null);
if (c.moveToFirst())
keydata = c.getBlob(0);
c.close();
try {
return PGP.readPublicKeyring(keydata);
}
catch (Exception e) {
// ignored
}
return null;
}
开发者ID:ShadiNachat,项目名称:Chatting-App-,代码行数:25,代码来源:UsersProvider.java
示例12: extractPublicKeyFromBytes
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的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
示例13: doInBackground
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
@Override
protected byte[] doInBackground(Void... strings) {
String email = SharedData.USERNAME;
char[] password = mKeyPassword.toCharArray();
try {
Log.d(TAG,"start generating keys");
PGPKeyRingGenerator keyRingGenerator = new KeyManagement().generateKey(email,password);
PGPPublicKeyRing publicKeys = keyRingGenerator.generatePublicKeyRing();
PGPSecretKeyRing secretKeys = keyRingGenerator.generateSecretKeyRing();
//output keys in ascii armored format
File file = new File(getFilesDir(),"pub.asc");
ArmoredOutputStream pubOut = new ArmoredOutputStream(new FileOutputStream(file));
publicKeys.encode(pubOut);
pubOut.close();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ArmoredOutputStream secOut = new ArmoredOutputStream(outputStream);
secretKeys.encode(secOut);
secOut.close();
DatabaseHandler db=new DatabaseHandler(OptionActivity.this,SharedData.DB_PASSWORD,true);
byte[] test=outputStream.toByteArray();
//call the db methods to store
db.insertSecKey(email,test);
SharedPreferences prefs=getSharedPreferences("done", Context.MODE_PRIVATE);
SharedPreferences.Editor editor=prefs.edit();
editor.putBoolean("keys_gen",true);
editor.apply();
editor.commit();
Log.d(TAG,"secret key written to file");
return test;
} catch (Exception e) {
Log.d(TAG,"Error generating keys");
e.printStackTrace();
return null;
}
}
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:41,代码来源:OptionActivity.java
示例14: readPublicKey
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的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
示例15: getPublicKey
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的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
示例16: getPublicKey
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
private static PGPPublicKey getPublicKey(PGPPublicKeyRing publicKeyRing) {
Iterator<?> kIt = publicKeyRing.getPublicKeys();
while (kIt.hasNext()) {
PGPPublicKey k = (PGPPublicKey) kIt.next();
if (k.isEncryptionKey()) {
return k;
}
}
return null;
}
开发者ID:guardianproject,项目名称:proofmode,代码行数:11,代码来源:PgpUtils.java
示例17: getTrustedPublicKeyRing
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
public PGPPublicKeyRing getTrustedPublicKeyRing() {
try {
if (mTrustedKeyRing != null)
return mTrustedKeyRing.getPublicKeyRing();
}
catch (Exception e) {
// ignored for now
Log.w(TAG, "unable to load public keyring", e);
}
return null;
}
开发者ID:kontalk,项目名称:androidclient,代码行数:12,代码来源:Contact.java
示例18: handlePresence
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
private void handlePresence(final Presence p) {
queueTask(new Runnable() {
@Override
public void run() {
updateUsersDatabase(p);
// request the new key if fingerprint changed
String newFingerprint = PublicKeyPresence.getFingerprint(p);
if (newFingerprint != null) {
boolean requestKey = false;
String jid = p.getFrom().asBareJid().toString();
PGPPublicKeyRing pubRing = Keyring.getPublicKey(getContext(),
jid, MyUsers.Keys.TRUST_UNKNOWN);
if (pubRing != null) {
String oldFingerprint = PGP.getFingerprint(PGP.getMasterKey(pubRing));
if (!newFingerprint.equalsIgnoreCase(oldFingerprint)) {
// key has changed, request new one
requestKey = true;
}
}
else {
// no key available, request one
requestKey = true;
}
if (requestKey)
MessageCenterService.requestPublicKey(getContext(), jid);
}
Intent i = createIntent(getContext(), p, getRosterEntry(p.getFrom()));
sendBroadcast(i);
}
});
}
开发者ID:kontalk,项目名称:androidclient,代码行数:35,代码来源:PresenceListener.java
示例19: loadArmored
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
public static PGPKeyPairRing loadArmored(byte[] privateKeyData, byte[] publicKeyData)
throws IOException, PGPException {
ArmoredInputStream inPublic = new ArmoredInputStream(new ByteArrayInputStream(publicKeyData));
PGPPublicKeyRing publicKey = new PGPPublicKeyRing(inPublic, sFingerprintCalculator);
ArmoredInputStream inPrivate = new ArmoredInputStream(new ByteArrayInputStream(privateKeyData));
PGPSecretKeyRing secretKey = new PGPSecretKeyRing(inPrivate, sFingerprintCalculator);
return new PGPKeyPairRing(publicKey, secretKey);
}
开发者ID:kontalk,项目名称:androidclient,代码行数:9,代码来源:PGP.java
示例20: getMasterKey
import org.spongycastle.openpgp.PGPPublicKeyRing; //导入依赖的package包/类
/** Returns the first master key found in the given public keyring. */
public static PGPPublicKey getMasterKey(PGPPublicKeyRing publicKeyring) {
@SuppressWarnings("unchecked")
Iterator<PGPPublicKey> iter = publicKeyring.getPublicKeys();
while (iter.hasNext()) {
PGPPublicKey pk = iter.next();
if (pk.isMasterKey())
return pk;
}
return null;
}
开发者ID:kontalk,项目名称:androidclient,代码行数:13,代码来源:PGP.java
注:本文中的org.spongycastle.openpgp.PGPPublicKeyRing类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论