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


Java PGPKeyPair.getPublicKey方法代码示例

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


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

示例1: provideKeyring

import org.bouncycastle.openpgp.PGPKeyPair; //导入方法依赖的package包/类
/** Always returns a {@link InMemoryKeyring} instance. */
@Provides
static Keyring provideKeyring() {
  PGPKeyPair dummyKey;
  try (InputStream publicInput = PGP_PUBLIC_KEYRING.openStream();
      InputStream privateInput = PGP_PRIVATE_KEYRING.openStream()) {
    PGPPublicKeyRingCollection publicKeys =
        new BcPGPPublicKeyRingCollection(PGPUtil.getDecoderStream(publicInput));
    PGPSecretKeyRingCollection privateKeys =
        new BcPGPSecretKeyRingCollection(PGPUtil.getDecoderStream(privateInput));
    dummyKey = lookupKeyPair(publicKeys, privateKeys, EMAIL_ADDRESS, ENCRYPT_SIGN);
  } catch (PGPException | IOException e) {
    throw new VerifyException("Failed to load PGP keys from jar", e);
  }
  // Use the same dummy PGP keypair for all required PGP keys -- a real production system would
  // have different values for these keys.  Pass dummy values for all Strings.
  return new InMemoryKeyring(
      dummyKey,
      dummyKey,
      dummyKey.getPublicKey(),
      dummyKey,
      dummyKey.getPublicKey(),
      "not a real key",
      "not a real key",
      "not a real password",
      "not a real login",
      "not a real password",
      "not a real login",
      "not a real credential",
      "not a real key");
}
 
开发者ID:google,项目名称:nomulus,代码行数:32,代码来源:DummyKeyringModule.java

示例2: testFailure_keyMismatch

import org.bouncycastle.openpgp.PGPKeyPair; //导入方法依赖的package包/类
@Test
public void testFailure_keyMismatch() throws Exception {
  FakeKeyringModule keyringModule = new FakeKeyringModule();
  byte[] data = "Fanatics have their dreams, wherewith they weave.".getBytes(UTF_8);
  DateTime mtime = DateTime.parse("1984-12-18T00:30:00Z");
  PGPKeyPair dsa1 = keyringModule.get("[email protected]", ENCRYPT);
  PGPKeyPair dsa2 = keyringModule.get("[email protected]", ENCRYPT);
  PGPPublicKey publicKey = dsa1.getPublicKey();
  PGPPrivateKey privateKey = dsa2.getPrivateKey();

  Ghostryde ghost = new Ghostryde(1024);
  ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
  try (Ghostryde.Encryptor encryptor = ghost.openEncryptor(bsOut, publicKey);
      Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor);
      OutputStream output = ghost.openOutput(kompressor, "lol", mtime)) {
    output.write(data);
  }

  ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
  PGPException thrown =
      expectThrows(
          PGPException.class,
          () -> {
            try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
              ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
            }
          });
  assertThat(thrown)
      .hasMessageThat()
      .contains("Message was encrypted for keyid a59c132f3589a1d5 but ours is c9598c84ec70b9fd");
}
 
开发者ID:google,项目名称:nomulus,代码行数:32,代码来源:GhostrydeTest.java

示例3: testFailure_keyCorruption

import org.bouncycastle.openpgp.PGPKeyPair; //导入方法依赖的package包/类
@Test
@Ignore("Intentionally corrupting a PGP key is easier said than done >_>")
public void testFailure_keyCorruption() throws Exception {
  FakeKeyringModule keyringModule = new FakeKeyringModule();
  byte[] data = "Fanatics have their dreams, wherewith they weave.".getBytes(UTF_8);
  DateTime mtime = DateTime.parse("1984-12-18T00:30:00Z");
  PGPKeyPair rsa = keyringModule.get("[email protected]", ENCRYPT);
  PGPPublicKey publicKey = rsa.getPublicKey();

  // Make the last byte of the private key off by one. muahahaha
  byte[] keyData = rsa.getPrivateKey().getPrivateKeyDataPacket().getEncoded();
  keyData[keyData.length - 1]++;
  PGPPrivateKey privateKey = new PGPPrivateKey(
      rsa.getKeyID(),
      rsa.getPrivateKey().getPublicKeyPacket(),
      rsa.getPrivateKey().getPrivateKeyDataPacket());

  Ghostryde ghost = new Ghostryde(1024);
  ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
  try (Ghostryde.Encryptor encryptor = ghost.openEncryptor(bsOut, publicKey);
      Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor);
      OutputStream output = ghost.openOutput(kompressor, "lol", mtime)) {
    output.write(data);
  }

  ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
  try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
    ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:31,代码来源:GhostrydeTest.java

示例4: PersonalKey

import org.bouncycastle.openpgp.PGPKeyPair; //导入方法依赖的package包/类
private PersonalKey(PGPKeyPair authKP,
        PGPKeyPair signKP,
        PGPKeyPair encryptKP,
        X509Certificate bridgeCert,
        String uid) throws PGPException {
    mAuthKey = authKP.getPublicKey();
    mLoginKey = PGPUtils.convertPrivateKey(authKP.getPrivateKey());
    mSignKey = signKP;
    mEncryptKey = encryptKP;
    mBridgeCert = bridgeCert;
    mUID = uid;
}
 
开发者ID:kontalk,项目名称:desktopclient-java,代码行数:13,代码来源:PersonalKey.java

示例5: createCertificate

import org.bouncycastle.openpgp.PGPKeyPair; //导入方法依赖的package包/类
public static X509Certificate createCertificate(PGPKeyPair keyPair, byte[] publicKeyRingData)
    throws InvalidKeyException, IllegalStateException, NoSuchAlgorithmException,
    SignatureException, CertificateException, NoSuchProviderException, PGPException, IOException, OperatorCreationException {

    X500NameBuilder x500NameBuilder = new X500NameBuilder();

    /*
     * The X.509 Name to be the subject DN is prepared.
     * The CN is extracted from the Secret Key user ID.
     */

    x500NameBuilder.addRDN(BCStyle.O, DN_COMMON_PART_O);

    PGPPublicKey publicKey = keyPair.getPublicKey();

    List<String> xmppAddrs = new LinkedList<>();
    for (@SuppressWarnings("unchecked") Iterator<Object> it = publicKey.getUserIDs(); it.hasNext();) {
        String attrib = it.next().toString();
        x500NameBuilder.addRDN(BCStyle.CN, attrib);
        // extract email for the subjectAltName
        String email = PGPUtils.parseUID(attrib)[2];
        if (!email.isEmpty())
            xmppAddrs.add(email);
    }

    X500Name x509name = x500NameBuilder.build();

    /*
     * To check the signature from the certificate on the recipient side,
     * the creation time needs to be embedded in the certificate.
     * It seems natural to make this creation time be the "not-before"
     * date of the X.509 certificate.
     * Unlimited PGP keys have a validity of 0 second. In this case,
     * the "not-after" date will be the same as the not-before date.
     * This is something that needs to be checked by the service
     * receiving this certificate.
     */
    Date creationTime = publicKey.getCreationTime();
    Date validTo = null;
    if (publicKey.getValidSeconds()>0)
       validTo = new Date(creationTime.getTime() + 1000L * publicKey.getValidSeconds());

    return createCertificate(
            PGPUtils.convertPublicKey(publicKey),
            PGPUtils.convertPrivateKey(keyPair.getPrivateKey()),
            x509name,
            creationTime, validTo,
            xmppAddrs,
            publicKeyRingData);
}
 
开发者ID:kontalk,项目名称:desktopclient-java,代码行数:51,代码来源:X509Bridge.java


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