Package java.security.spec

Examples of java.security.spec.RSAPublicKeySpec


      try {
         KeyFactory rsaFactory = KeyFactory.getInstance("RSA");

         // KeyFactory rsaFactory = KeyFactory.getInstance(JCE_RSA);
         RSAPublicKeySpec rsaKeyspec =
            new RSAPublicKeySpec(this
               .getBigIntegerFromChildElement(Constants._TAG_MODULUS, Constants
               .SignatureSpecNS), this
                  .getBigIntegerFromChildElement(Constants
                     ._TAG_EXPONENT, Constants.SignatureSpecNS));
         PublicKey pk = rsaFactory.generatePublic(rsaKeyspec);
View Full Code Here


   String expectedSha1 = "c8:01:34:c0:3c:8c:91:ac:e1:da:cf:72:15:d7:f2:e5:99:5b:28:d4";

   @Test
   public void testCanReadRsaAndCompareFingerprintOnPublicRSAKey() throws IOException {
      String pubKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test.pub"));
      RSAPublicKeySpec key = SshKeys.publicKeySpecFromOpenSSH(pubKey);
      String fingerPrint = fingerprint(key.getPublicExponent(), key.getModulus());
      assertEquals(fingerPrint, expectedFingerprint);
   }
View Full Code Here

   @Test
   public void testPrivateKeyMatchesPublicKeyTyped() throws IOException {
      String privKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test"));
      RSAPrivateCrtKeySpec privateKey = (RSAPrivateCrtKeySpec) Pems.privateKeySpec(privKey);
      String pubKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test.pub"));
      RSAPublicKeySpec publicKey = publicKeySpecFromOpenSSH(pubKey);
      assert privateKeyMatchesPublicKey(privateKey, publicKey);
   }
View Full Code Here

         checkArgument(size(parts) >= 2, "bad format, should be: [ssh-rsa|ssh-dss] AAAAB3...");
         String type = get(parts, 0);

         try {
            if ("ssh-rsa".equals(type)) {
               RSAPublicKeySpec spec = SshKeys.publicKeySpecFromOpenSSH(input);
               return KeyFactory.getInstance("RSA").generatePublic(spec);
            } else if ("ssh-dss".equals(type)) {
               DSAPublicKeySpec spec = DSAKeys.publicKeySpecFromOpenSSH(input);
               return KeyFactory.getInstance("DSA").generatePublic(spec);
            } else {
View Full Code Here

  }
  Element modulusElem = DOMUtils.getFirstChildElement(kvtElem);
        modulus = new DOMCryptoBinary(modulusElem.getFirstChild());
  Element exponentElem = DOMUtils.getNextSiblingElement(modulusElem);
        exponent = new DOMCryptoBinary(exponentElem.getFirstChild());
        RSAPublicKeySpec spec = new RSAPublicKeySpec
      (modulus.getBigNum(), exponent.getBigNum());
        return (RSAPublicKey) generatePublicKey(rsakf, spec);
    }
View Full Code Here

      try {
         KeyFactory rsaFactory = KeyFactory.getInstance("RSA");

         // String JCE_RSA = org.apache.xml.security.algorithms.JCEMapper.translateURItoJCEID(Constants.ALGO_ID_SIGNATURE_RSA);
         // KeyFactory rsaFactory = KeyFactory.getInstance(JCE_RSA);
         RSAPublicKeySpec rsaKeyspec =
            new RSAPublicKeySpec(this
               .getBigIntegerFromChildElement(Constants._TAG_MODULUS, Constants
               .SignatureSpecNS), this
                  .getBigIntegerFromChildElement(Constants
                     ._TAG_EXPONENT, Constants.SignatureSpecNS));
         PublicKey pk = rsaFactory.generatePublic((KeySpec) rsaKeyspec);
View Full Code Here

                    if (pos != rawKey.length) {
                        throw new IOException("Authorized keys file line " + reader.getLineNumber() + " contains a RSA key with extra garbage.");
                    }

                    RSAPublicKeySpec ps = new RSAPublicKeySpec(modulus, e);
                    pk = rsaKeyGen.generatePublic(ps);
                } else {
                    throw new IOException("Authorized keys file line " + reader.getLineNumber() + " does not start with ssh-dss or ssh-rsa.");
                }
               
View Full Code Here

  }
  Element modulusElem = DOMUtils.getFirstChildElement(kvtElem);
        modulus = new DOMCryptoBinary(modulusElem.getFirstChild());
  Element exponentElem = DOMUtils.getNextSiblingElement(modulusElem);
        exponent = new DOMCryptoBinary(exponentElem.getFirstChild());
        RSAPublicKeySpec spec = new RSAPublicKeySpec
      (modulus.getBigNum(), exponent.getBigNum());
        return (RSAPublicKey) generatePublicKey(rsakf, spec);
    }
View Full Code Here

        // Transform the PublicKey to be sure we have it in a format that the X509 certificate generator handles, it might be
        // a CVC public key that is passed as parameter
        PublicKey publicKey = null;
        if (pubKey instanceof RSAPublicKey) {
          RSAPublicKey rsapk = (RSAPublicKey)pubKey;
        RSAPublicKeySpec rSAPublicKeySpec = new RSAPublicKeySpec(rsapk.getModulus(), rsapk.getPublicExponent());       
        try {
        publicKey = KeyFactory.getInstance("RSA").generatePublic(rSAPublicKeySpec);
      } catch (InvalidKeySpecException e) {
        log.error("Error creating RSAPublicKey from spec: ", e);
        publicKey = pubKey;
View Full Code Here

        JAXBElement<RegisterRequestType> registerRequest2 = (JAXBElement<RegisterRequestType>) unmarshaller.unmarshal(bais);
        registerRequestType = registerRequest2.getValue();
       
        RSAKeyValueType rSAKeyValueType  = (RSAKeyValueType) ((JAXBElement) registerRequestType.getPrototypeKeyBinding().getKeyInfo().getContent().get(0)).getValue();       
        RSAPublicKeySpec rSAPublicKeySpec = new RSAPublicKeySpec(new BigInteger(rSAKeyValueType.getModulus()), new BigInteger(rSAKeyValueType.getExponent()));       
        RSAPublicKey rSAPublicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(rSAPublicKeySpec);
       
        X509Certificate cert = CertTools.genSelfCert("CN=test", 10, null,keys.getPrivate(), rSAPublicKey, "SHA1WithRSA", true);
       
        cert.verify(rSAPublicKey)
View Full Code Here

TOP

Related Classes of java.security.spec.RSAPublicKeySpec

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.