Package java.security.interfaces

Examples of java.security.interfaces.RSAPublicKey


  {
    SecretKeySpec blowfishKey = null;
    try {
      X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(PUBLIC_KEY);
      KeyFactory keyFactory = KeyFactory.getInstance("RSA");
      RSAPublicKey publicKey = (RSAPublicKey)keyFactory.generatePublic(publicKeySpec);

      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.DECRYPT_MODE, publicKey);

      byte[] blowfishKeyByteArray = cipher.doFinal(encryptedKey);
View Full Code Here


  {
    byte[] returnByteArray = null;
    try {
      X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(PUBLIC_KEY);
      KeyFactory keyFactory = KeyFactory.getInstance("RSA");
      RSAPublicKey publicKey = (RSAPublicKey)keyFactory.generatePublic(publicKeySpec);

      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.ENCRYPT_MODE, publicKey);

      returnByteArray = cipher.doFinal(blowfishKey.getEncoded());
View Full Code Here

    KeyFactory key_factory = KeyFactory.getInstance("RSA");
   
    RSAPublicKeySpec   public_key_spec =
      new RSAPublicKeySpec( new BigInteger(modulus,16), new BigInteger(pub_exp,16));

    RSAPublicKey public_key   = (RSAPublicKey)key_factory.generatePublic( public_key_spec );

    verifyData( file, public_key );
  }
View Full Code Here

    KeyFactory key_factory = KeyFactory.getInstance("RSA");
   
    RSAPublicKeySpec   public_key_spec =
      new RSAPublicKeySpec( new BigInteger(modulus,16), new BigInteger(pub_exp,16));

    RSAPublicKey public_key   = (RSAPublicKey)key_factory.generatePublic( public_key_spec );
   
    Signature  sig = Signature.getInstance("MD5withRSA" );

    sig.initVerify( public_key );
   
View Full Code Here

           {
                   return new X509EncodedKeySpec(key.getEncoded());
           }
           else if (spec.isAssignableFrom(RSAPublicKeySpec.class) && key instanceof RSAPublicKey)
           {
                RSAPublicKey    k = (RSAPublicKey)key;

                return new RSAPublicKeySpec(k.getModulus(), k.getPublicExponent());
           }
           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;

                return new RSAPrivateCrtKeySpec(
                                k.getModulus(), k.getPublicExponent(),
                                k.getPrivateExponent(),
                                k.getPrimeP(), k.getPrimeQ(),
                                k.getPrimeExponentP(), k.getPrimeExponentQ(),
                                k.getCrtCoefficient());
           }


            throw new RuntimeException("not implemented yet " + key + " " + spec);
        }
View Full Code Here

    if ( o == this )
    {
      return true;
    }

    RSAPublicKey key = (RSAPublicKey)o;

    return getModulus().equals(key.getModulus())
      && getPublicExponent().equals(key.getPublicExponent());
  }
View Full Code Here

        String exponentText = publicKey.substring(0x100);
        BigInteger modulus  = new BigInteger(1, ConvertHelper.hexString2ByteNoSpace(modulusText));
        BigInteger exponent = new BigInteger(1, ConvertHelper.hexString2ByteNoSpace(exponentText));
      KeyFactory keyFactory = KeyFactory.getInstance("RSA");  
      RSAPublicKeySpec bobPubKeySpec = new RSAPublicKeySpec(modulus, exponent);  
      RSAPublicKey rsapublicKey = (RSAPublicKey) keyFactory.generatePublic(bobPubKeySpec);  
        return  rsapublicKey;
   
View Full Code Here

        InputStream inStream = new ByteArrayInputStream(PublicKey.getCertificate());
        CertificateFactory cf;
        try {
            cf = CertificateFactory.getInstance("X.509");
            X509Certificate cert = (X509Certificate) cf.generateCertificate(inStream);
            RSAPublicKey key = (RSAPublicKey) cert.getPublicKey();

            Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            cipher.init(Cipher.ENCRYPT_MODE, key);

            byte[] cipherText = cipher.doFinal(this.body.getBytes());
View Full Code Here

        if (privKey.hashCode() != crtKey.hashCode())
        {
            fail("private key hashCode check failed");
        }

        RSAPublicKey copyKey = (RSAPublicKey)keyFact.translateKey(pubKey);
       
        if (!pubKey.equals(copyKey))
        {
            fail("public key equality check failed");
        }

        copyKey = (RSAPublicKey)keyFact.generatePublic(new X509EncodedKeySpec(pubKey.getEncoded()));

        if (!pubKey.equals(copyKey))
        {
            fail("public key equality check failed");
        }

        copyKey = (RSAPublicKey)serializeDeserialize(pubKey);

        if (!pubKey.equals(copyKey))
        {
            fail("public key equality check failed");
        }

        if (pubKey.hashCode() != copyKey.hashCode())
        {
            fail("public key hashCode check failed");
        }

        oaepCompatibilityTest("SHA-1", priv2048Key, pub2048Key);
View Full Code Here

        gen.initialize(1024, new SecureRandom());

        KeyPair         pair = gen.generateKeyPair();
        RSAPrivateKey   privKey = (RSAPrivateKey)pair.getPrivate();
        RSAPublicKey    pubKey = (RSAPublicKey)pair.getPublic();
        BigInteger      modulus = privKey.getModulus();
        BigInteger      privateExponent = privKey.getPrivateExponent();


        //
View Full Code Here

TOP

Related Classes of java.security.interfaces.RSAPublicKey

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.