当前位置: 首页>>代码示例>>Java>>正文


Java PGPPublicKeyRingCollection.getPublicKey方法代码示例

本文整理汇总了Java中org.bouncycastle.openpgp.PGPPublicKeyRingCollection.getPublicKey方法的典型用法代码示例。如果您正苦于以下问题:Java PGPPublicKeyRingCollection.getPublicKey方法的具体用法?Java PGPPublicKeyRingCollection.getPublicKey怎么用?Java PGPPublicKeyRingCollection.getPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.openpgp.PGPPublicKeyRingCollection的用法示例。


在下文中一共展示了PGPPublicKeyRingCollection.getPublicKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getKey

import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
public PGPPublicKey getKey(long keyID) throws IOException, PGPException {

        File keyFile = null;
        PGPPublicKey key = null;

        try {
            String path = String.format("%02X/%02X/%016X.asc",
                    (byte) (keyID >> 56), (byte) (keyID >> 48 & 0xff), keyID);

            keyFile = new File(cachePath, path);
            if (!keyFile.exists()) {
                receiveKey(keyFile, keyID);
            }

            InputStream keyIn = PGPUtil.getDecoderStream(new FileInputStream(keyFile));
            PGPPublicKeyRingCollection pgpRing = new PGPPublicKeyRingCollection(keyIn, new BcKeyFingerprintCalculator());
            key = pgpRing.getPublicKey(keyID);
        } finally {
            if (key == null) {
                deleteFile(keyFile);
            }
        }
        return key;
    }
 
开发者ID:netmackan,项目名称:java-binrepo-proxy,代码行数:25,代码来源:PGPKeysCache.java

示例2: getKey

import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
PGPPublicKey getKey(long keyID) throws IOException, PGPException {

        File keyFile = null;
        PGPPublicKey key = null;

        try {
            String path = String.format("%02X/%02X/%016X.asc",
                    (byte) (keyID >> 56), (byte) (keyID >> 48 & 0xff), keyID);

            keyFile = new File(cachePath, path);
            if (!keyFile.exists()) {
                receiveKey(keyFile, keyID);
            }

            InputStream keyIn = PGPUtil.getDecoderStream(new FileInputStream(keyFile));
            PGPPublicKeyRingCollection pgpRing = new PGPPublicKeyRingCollection(keyIn, new BcKeyFingerprintCalculator());
            key = pgpRing.getPublicKey(keyID);
        } finally {
            if (key == null) {
                deleteFile(keyFile);
            }
        }
        return key;
    }
 
开发者ID:s4u,项目名称:pgpverify-maven-plugin,代码行数:25,代码来源:PGPKeysCache.java

示例3: findPublicKeyWithKeyId

import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
private static PGPPublicKey findPublicKeyWithKeyId(InputStream input, long keyid) throws IOException, PGPException,
        NoSuchProviderException {
    PGPPublicKeyRingCollection pgpSec = 
        new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(input),
                                       new BcKeyFingerprintCalculator());
    return pgpSec.getPublicKey(keyid);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:PGPDataFormatUtil.java

示例4: encrypt

import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
public static final byte[] encrypt(File pubring, long keyid, byte[] in){
	if(!pubring.exists() || !pubring.isFile()) return null;
	
	try {
		byte[] ret = null;
		
		FileInputStream fis = new FileInputStream(pubring);
		InputStream is = PGPUtil.getDecoderStream(fis);
        PGPPublicKeyRingCollection ring = new PGPPublicKeyRingCollection(is);
        PGPPublicKey pubkey = ring.getPublicKey(keyid);
		if(pubkey.isMasterKey()) {
			System.err.println("Tried to use a non-encryption key. This should never happen.");
			return null;
		}

        PublicKey key = new JcaPGPKeyConverter().getPublicKey(pubkey);
	    Cipher cipher = Cipher.getInstance(key.getAlgorithm() + "/ECB/PKCS1Padding");
	    cipher.init(Cipher.ENCRYPT_MODE, key);
	    ret = cipher.doFinal(in);
        
        is.close();
        fis.close();
		
		return ret;
	} catch (Exception e) {
		System.err.println(e.getLocalizedMessage());
		return null;
	}
}
 
开发者ID:fhissen,项目名称:CrococryptFile,代码行数:30,代码来源:PGPUtils.java

示例5: validateLicense

import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
/**
 * Validate pgp signature of license
 * 
 * @param licenseText base64 encoded pgp signed license
 * @return The plain license in json (if validation is successful)
 * @throws PGPException if validation fails
 */
public static String validateLicense(String licenseText) throws PGPException {
    
	licenseText = licenseText.trim().replaceAll("\\r|\\n", "");
    licenseText = licenseText.replace("---- SCHNIPP (Armored PGP signed JSON as base64) ----","");
    licenseText = licenseText.replace("---- SCHNAPP ----","");
    
    try {
        final byte[] armoredPgp = BaseEncoding.base64().decode(licenseText);

        final ArmoredInputStream in = new ArmoredInputStream(new ByteArrayInputStream(armoredPgp));

        //
        // read the input, making sure we ignore the last newline.
        //
        // https://github.com/bcgit/bc-java/blob/master/pg/src/test/java/org/bouncycastle/openpgp/test/PGPClearSignedSignatureTest.java

        final ByteArrayOutputStream bout = new ByteArrayOutputStream();
        int ch;

        while ((ch = in.read()) >= 0 && in.isClearText()) {
            bout.write((byte) ch);
        }

        final KeyFingerPrintCalculator c = new BcKeyFingerprintCalculator();

        final PGPObjectFactory factory = new PGPObjectFactory(in, c);
        final PGPSignatureList sigL = (PGPSignatureList) factory.nextObject();
        final PGPPublicKeyRingCollection pgpRings = new PGPPublicKeyRingCollection(new ArmoredInputStream(
                LicenseHelper.class.getResourceAsStream("/KEYS")), c);

        if (sigL == null || pgpRings == null || sigL.size() == 0 || pgpRings.size() == 0) {
            throw new PGPException("Cannot find license signature");
        }

        final PGPSignature sig = sigL.get(0);
        final PGPPublicKey publicKey = pgpRings.getPublicKey(sig.getKeyID());

        if (publicKey == null || sig == null) {
            throw new PGPException("license signature key mismatch");
        }

        sig.init(new BcPGPContentVerifierBuilderProvider(), publicKey);

        final ByteArrayOutputStream lineOut = new ByteArrayOutputStream();
        final InputStream sigIn = new ByteArrayInputStream(bout.toByteArray());
        int lookAhead = readInputLine(lineOut, sigIn);

        processLine(sig, lineOut.toByteArray());

        if (lookAhead != -1) {
            do {
                lookAhead = readInputLine(lineOut, lookAhead, sigIn);

                sig.update((byte) '\r');
                sig.update((byte) '\n');

                processLine(sig, lineOut.toByteArray());
            } while (lookAhead != -1);
        }

        if (!sig.verify()) {
            throw new PGPException("Invalid license signature");
        }

        return bout.toString();
    } catch (final Exception e) {
        throw new PGPException(e.toString(), e);
    }
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:77,代码来源:LicenseHelper.java

示例6: getPublicKey

import org.bouncycastle.openpgp.PGPPublicKeyRingCollection; //导入方法依赖的package包/类
/**
 * Get a public key from a public key block.
 *
 * @param block the public key block
 * @param keyID the key id
 * @return the public key
 * @throws Exception anything that would prevent to obtain the key
 */
public static PGPPublicKey getPublicKey(byte[] block, long keyID) throws Exception {
  InputStream keyIn = PGPUtil.getDecoderStream(new ByteArrayInputStream(block));
  PGPPublicKeyRingCollection pgpRing = new PGPPublicKeyRingCollection(keyIn, new BcKeyFingerprintCalculator());
  return pgpRing.getPublicKey(keyID);
}
 
开发者ID:vert-x3,项目名称:vertx-http-service-factory,代码行数:14,代码来源:PGPHelper.java


注:本文中的org.bouncycastle.openpgp.PGPPublicKeyRingCollection.getPublicKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。