Package java.security.spec

Examples of java.security.spec.PKCS8EncodedKeySpec


        String f2 = p3.getFormat();
        harness.check("PKCS#8".equalsIgnoreCase(f2),
                      "DSS private key format MUST be PKCS#8");
        byte[] encoded2 = p3.getEncoded();

        PKCS8EncodedKeySpec spec2 = new PKCS8EncodedKeySpec(encoded2);
        PrivateKey p4 = encodedKF.generatePrivate(spec2);
        harness.check(p3.equals(p4), "Two DSS private keys MUST be equal");
      }
    catch (Exception x)
      {
View Full Code Here


        String f2 = p3.getFormat();
        harness.check("PKCS#8".equalsIgnoreCase(f2),
                      "RSA private key format MUST be PKCS#8");
        byte[] encoded2 = p3.getEncoded();

        PKCS8EncodedKeySpec spec2 = new PKCS8EncodedKeySpec(encoded2);
        PrivateKey p4 = encodedKF.generatePrivate(spec2);
        harness.check(p3.equals(p4), "Two RSA private keys MUST be equal");
      }
    catch (Exception x)
      {
View Full Code Here

        String f2 = p3.getFormat();
        harness.check("PKCS#8".equalsIgnoreCase(f2),
                      "DH private key format MUST be PKCS#8");
        byte[] encoded2 = p3.getEncoded();

        PKCS8EncodedKeySpec spec2 = new PKCS8EncodedKeySpec(encoded2);
        PrivateKey p4 = encodedKF.generatePrivate(spec2);
        harness.check(p3.equals(p4), "Two DH private keys MUST be equal");
      }
    catch (Exception x)
      {
View Full Code Here

        X509EncodedKeySpec spec1 = new X509EncodedKeySpec(encoded);
        PublicKey k1 = keyFactory.generatePublic(spec1);
        harness.check(k1.equals(publicK), "Public DSS keys MUST be equal");

        encoded = privateK.getEncoded();
        PKCS8EncodedKeySpec spec2 = new PKCS8EncodedKeySpec(encoded);
        PrivateKey k2 = keyFactory.generatePrivate(spec2);
        harness.check(k2.equals(privateK), "Private DSS keys MUST be equal");
      }
    catch (InvalidKeySpecException x)
      {
View Full Code Here

        X509EncodedKeySpec spec1 = new X509EncodedKeySpec(encoded);
        PublicKey k1 = keyFactory.generatePublic(spec1);
        harness.check(k1.equals(publicK), "Public DH keys MUST be equal");

        encoded = privateK.getEncoded();
        PKCS8EncodedKeySpec spec2 = new PKCS8EncodedKeySpec(encoded);
        PrivateKey k2 = keyFactory.generatePrivate(spec2);
        harness.check(k2.equals(privateK), "Private DH keys MUST be equal");
      }
    catch (InvalidKeySpecException x)
      {
View Full Code Here

    Section section = PemReader.readFirstSectionAndClose(reader, "PRIVATE KEY");
    if (section == null) {
      throw new IOException("Invalid PKCS8 data.");
    }
    byte[] bytes = section.getBase64DecodedBytes();
    PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytes);
    Exception unexpectedException = null;
    try {
      KeyFactory keyFactory = SecurityUtils.getRsaKeyFactory();
      PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
      return privateKey;
View Full Code Here

    public Builder setServiceAccountPrivateKeyFromPemFile(File pemFile)
        throws GeneralSecurityException, IOException {
      byte[] bytes = PemReader.readFirstSectionAndClose(new FileReader(pemFile), "PRIVATE KEY")
          .getBase64DecodedBytes();
      serviceAccountPrivateKey =
          SecurityUtils.getRsaKeyFactory().generatePrivate(new PKCS8EncodedKeySpec(bytes));
      return this;
    }
View Full Code Here

    private PrivateKey readPrivateKeyFromFile(String fileName) throws IOException {
        InputStream base64InputStream = new Base64.InputStream(getClass().getResourceAsStream(fileName));
        byte[] data = new byte[base64InputStream.available()];
        base64InputStream.read(data);
        PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(data);
        try {
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            return keyFactory.generatePrivate(privateKeySpec);
        } catch (NoSuchAlgorithmException e) {
            throw new EveManageSecurityException(e);
View Full Code Here

        } catch (ClassCastException e) {
          log.error("ClassCastException setting BagAttributes, can not set friendly name: ", e);
        }
        // "Clean" private key, i.e. remove any old attributes
        final KeyFactory keyfact = KeyFactory.getInstance(privKey.getAlgorithm(), "BC");
        final PrivateKey pk = keyfact.generatePrivate(new PKCS8EncodedKeySpec(privKey.getEncoded()));
        // Set attributes for private key
        try {
          final PKCS12BagAttributeCarrier keyBagAttr = (PKCS12BagAttributeCarrier) pk;
          // in this case we just set the local key id to that of the public key
          keyBagAttr.setBagAttribute(PKCSObjectIdentifiers.pkcs_9_at_friendlyName, new DERBMPString(alias));
View Full Code Here

    CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
    return (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(certroottest));
  }
 
  public static PrivateKey getUserKey() throws Exception{
        PKCS8EncodedKeySpec pkKeySpec = new PKCS8EncodedKeySpec(userkey);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        return keyFactory.generatePrivate(pkKeySpec);
  }
View Full Code Here

TOP

Related Classes of java.security.spec.PKCS8EncodedKeySpec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.