Examples of RSAPrivateKeySpec


Examples of java.security.spec.RSAPrivateKeySpec

            BigInteger  pub = new BigInteger("03", 16);
            BigInteger  pri = new BigInteger("2aaaaaaa942920e38120ee965168302fd0301d73a4e60c7143ceb0adf0bf30b9352f50e8b9e4ceedd65343b2179005b2f099915e4b0c37e41314bb0821ad8330d23cba7f589e0f129b04c46b67dfce9d", 16);

            KeyFactory  f = KeyFactory.getInstance("RSA", "BC");

            PrivateKey  privKey = f.generatePrivate(new RSAPrivateKeySpec(mod, pri));
            PublicKey   pubKey = f.generatePublic(new RSAPublicKeySpec(mod, pub));
            byte[]      testSig = Hex.decode("5cf9a01854dbacaec83aae8efc563d74538192e95466babacd361d7c86000fe42dcb4581e48e4feb862d04698da9203b1803b262105104d510b365ee9c660857ba1c001aa57abfd1c8de92e47c275cae");

            data = Hex.decode("fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210");
View Full Code Here

Examples of java.security.spec.RSAPrivateKeySpec

       }
       else if (spec.isAssignableFrom(RSAPrivateKeySpec.class) && key instanceof RSAPrivateKey)
       {
            RSAPrivateKey    k = (RSAPrivateKey)key;

            return new RSAPrivateKeySpec(k.getModulus(), k.getPrivateExponent());
       }
       else if (spec.isAssignableFrom(RSAPrivateCrtKeySpec.class) && key instanceof RSAPrivateCrtKey)
       {
            RSAPrivateCrtKey    k = (RSAPrivateCrtKey)key;
View Full Code Here

Examples of java.security.spec.RSAPrivateKeySpec

                    "ae009d30cfdf6acb5b6a64cdc730bc630a39d946d08babffe62ea20a87e37c93b3b0e8a8e576045b" +
                    "bddfbde83ca9bfa180fe6a5f5eee60661936d728314e809201ef52cd71d9fa3c8ce83f9d30ab5e08" +
                    "1539219e7e45dd6a60be65ac95d2049b8f21", 16),
                new BigInteger("10001", 16));
       
        RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(
                new BigInteger(
                    "8710a2bcb2f3fdac177f0ae0461c2dd0ebf72e0d88a5400583a7d8bdabd" +
                    "6ae009d30cfdf6acb5b6a64cdc730bc630a39d946d08babffe62ea20a87e37c93b3b0e8a8e576045" +
                    "bbddfbde83ca9bfa180fe6a5f5eee60661936d728314e809201ef52cd71d9fa3c8ce83f9d30ab5e0" +
                    "81539219e7e45dd6a60be65ac95d2049b8f21", 16),
View Full Code Here

Examples of java.security.spec.RSAPrivateKeySpec

     * Test for <code>RSAPrivateKeySpec(BigInteger,BigInteger)</code> ctor
     * Assertion: constructs <code>RSAPrivateKeySpec</code>
     * object using valid parameters
     */
    public final void testRSAPrivateKeySpec() {
        KeySpec ks = new RSAPrivateKeySpec(BigInteger.valueOf(1234567890L),
                                           BigInteger.valueOf(3L));
        assertTrue(ks instanceof RSAPrivateKeySpec);
    }
View Full Code Here

Examples of java.security.spec.RSAPrivateKeySpec

    /**
     * Test for <code>getModulus()</code> method<br>
     * Assertion: returns modulus
     */
    public final void testGetModulus() {
        RSAPrivateKeySpec rpks =
            new RSAPrivateKeySpec(BigInteger.valueOf(1234567890L),
                                  BigInteger.valueOf(3L));
        assertEquals(1234567890L, rpks.getModulus().longValue());
    }
View Full Code Here

Examples of java.security.spec.RSAPrivateKeySpec

    /**
     * Test for <code>getPrivateExponent()</code> method<br>
     * Assertion: returns private exponent
     */
    public final void testGetPrivateExponent() {
        RSAPrivateKeySpec rpks =
            new RSAPrivateKeySpec(BigInteger.valueOf(1234567890L),
                                  BigInteger.valueOf(3L));
        assertEquals(3L, rpks.getPrivateExponent().longValue());
    }
View Full Code Here

Examples of java.security.spec.RSAPrivateKeySpec

          kpg.initialize(keySize);
          KeyPair kp = kpg.genKeyPair();
          KeyFactory keyFactory = KeyFactory.getInstance(keyType);
          RSAPublicKeySpec pub = keyFactory.getKeySpec(kp.getPublic(), RSAPublicKeySpec.class);
          // <IBM JDK does not seem to support RSAPrivateKeySpec.class>
          RSAPrivateKeySpec pvt;
          try {
            pvt = keyFactory.getKeySpec(kp.getPrivate(), RSAPrivateKeySpec.class);
          }
          catch(Exception e) {
            pvt = keyFactory.getKeySpec(kp.getPrivate(), RSAPrivateCrtKeySpec.class);
          }
          // </IBM JDK does not seem to support RSAPrivateKeySpec.class>
          putKeyToFile(filePub, pub.getModulus(), pub.getPublicExponent(),pubFilePermissions);
          putKeyToFile(filePvt, pvt.getModulus(), pvt.getPrivateExponent(),pvtFilePermissions);
        }
      }
    }
    catch(CryptoException e) {
      throw e;
View Full Code Here

Examples of java.security.spec.RSAPrivateKeySpec

            KeyFactory keyFactory = KeyFactory.getInstance(keyType);
            PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
            return publicKey;
          }
         
          RSAPrivateKeySpec spec = new RSAPrivateKeySpec(publicKeySpec.getModulus(),publicKeySpec.getPublicExponent());
          Key key = KeyFactory.getInstance("RSA").generatePrivate(spec);
         
          return key;
      }
      finally {
View Full Code Here

Examples of java.security.spec.RSAPrivateKeySpec

      String fileName = filePvt;
      ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(fileName)));
      try {
        BigInteger mod = (BigInteger) ois.readObject();
          BigInteger exp = (BigInteger) ois.readObject();
          RSAPrivateKeySpec privateKeySpec = new RSAPrivateKeySpec(mod, exp);
         
          if(traditional) {
            KeyFactory keyFactory = KeyFactory.getInstance(keyType);
            PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);
            return privateKey;
          }
         
          RSAPublicKeySpec spec = new RSAPublicKeySpec(privateKeySpec.getModulus(),privateKeySpec.getPrivateExponent());
          Key key = KeyFactory.getInstance("RSA").generatePublic(spec);

          return key;
      }
      finally {
View Full Code Here

Examples of java.security.spec.RSAPrivateKeySpec

       }
       else if (spec.isAssignableFrom(RSAPrivateKeySpec.class) && key instanceof RSAPrivateKey)
       {
            RSAPrivateKey    k = (RSAPrivateKey)key;

            return new RSAPrivateKeySpec(k.getModulus(), k.getPrivateExponent());
       }
       else if (spec.isAssignableFrom(RSAPrivateCrtKeySpec.class) && key instanceof RSAPrivateCrtKey)
       {
            RSAPrivateCrtKey    k = (RSAPrivateCrtKey)key;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.