Package java.security.interfaces

Examples of java.security.interfaces.RSAPrivateKey


      /*
       * 利用RSA私钥解密DES密钥
       */
      RSAEncrypter encrypt1 = new RSAEncrypter();
      String privateKeyPath = "D:/hdfs/29/privateKey";
      RSAPrivateKey priKey = (RSAPrivateKey) encrypt1.loadKey(
          privateKeyPath, 0);
      byte[] originDESKey = encrypt1.decrypt(priKey, encryptDESKey);
      System.out.println("解密后的DES密钥:" + new String(originDESKey));

    } catch (Exception e) {
View Full Code Here


                    "5187cb9a50fa828e5efe51d52f5d112c20bc700b836facadca6e0051afcdfe866841e37d207c0295" +
                    "36ff8674b301e2198b2c56abb0a0313f8ff84c1fcd6fa541aa6e5d9c018fab4784d2940def5dc709" +
                    "ddc714d73b6c23b5d178eaa5933577b8e8ae9", 16));
       
        RSAPublicKey pubKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec);
        RSAPrivateKey privKey = (RSAPrivateKey) keyFactory.generatePrivate(privKeySpec);

        // Encrypt the data encryption key with the key encryption key
        XMLCipher keyCipher = XMLCipher.getInstance(XMLCipher.RSA_v1dot5);
        keyCipher.init(XMLCipher.WRAP_MODE, pubKey);
        EncryptedKey encryptedKey = keyCipher.encryptKey(document, dataEncryptKey);
View Full Code Here

        putBigIntAsBase64UrlEncodedParam(params, EXPONENT_MEMBER_NAME, rsaPublicKey.getPublicExponent());
    }

    protected void fillPrivateTypeSpecificParams(Map<String,Object> params)
    {
        RSAPrivateKey rsaPrivateKey = getRsaPrivateKey();
       
        if (rsaPrivateKey != null)
        {
            putBigIntAsBase64UrlEncodedParam(params, PRIVATE_EXPONENT_MEMBER_NAME, rsaPrivateKey.getPrivateExponent());

          if (rsaPrivateKey instanceof RSAPrivateCrtKey)
          {
              RSAPrivateCrtKey crt = (RSAPrivateCrtKey) rsaPrivateKey;
              putBigIntAsBase64UrlEncodedParam(params, FIRST_PRIME_FACTOR_MEMBER_NAME, crt.getPrimeP());
View Full Code Here

    }

    @Override
    public void validateDecryptionKey(Key managementKey, ContentEncryptionAlgorithm contentEncryptionAlg) throws InvalidKeyException
    {
        RSAPrivateKey rsaPrivateKey = KeyValidationSupport.castKey(managementKey, RSAPrivateKey.class);
        KeyValidationSupport.checkRsaKeySize(rsaPrivateKey);
    }
View Full Code Here

        }
    }

    @Test
    public void pvtKeySerialisationTest() throws Exception{
        RSAPrivateKey pvtKey = TrCrypto.createRsaKeyPair().b;
        try{

            final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
            final DataOutputStream dos = new DataOutputStream(baos);

            TrSerializer.serializeTo(pvtKey, dos);

            final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
            RSAPrivateKey pvtKey1 = TrSerializer.deserializeFrom(RSAPrivateKey.class, dis);

            Assert.assertEquals(pvtKey1, pvtKey);
        } catch (IOException e) {
            e.printStackTrace();
        }
View Full Code Here

        InvalidKeySpecException, NoSuchProviderException
    {
        // Build an RSA private key from private key data
        PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(derPrivateKeyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        RSAPrivateKey privateKey = (RSAPrivateKey) keyFactory.generatePrivate(privSpec);

        // Sign data
        Signature signature = Signature.getInstance("SHA1withRSA", "BC");
        signature.initSign(privateKey, new SecureRandom());
        signature.update(dataToSign);
View Full Code Here

    }
  }

  @Override
  protected void serialize(final Type type, final Object object, final DataOutputStream dos) throws IOException {
    final RSAPrivateKey key = (RSAPrivateKey) object;
    final byte[] encoded = new PKCS8EncodedKeySpec(key.getEncoded()).getEncoded();
    dos.writeInt(encoded.length);
    dos.write(encoded);
  }
View Full Code Here

            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());
       }
       else if (spec.isAssignableFrom(DHPrivateKeySpec.class) && key instanceof DHPrivateKey)
       {
           DHPrivateKey k = (DHPrivateKey)key;
          
           return new DHPrivateKeySpec(k.getX(), k.getParams().getP(), k.getParams().getG());
       }
       else if (spec.isAssignableFrom(DHPublicKeySpec.class) && key instanceof DHPublicKey)
       {
           DHPublicKey k = (DHPublicKey)key;
          
           return new DHPublicKeySpec(k.getY(), k.getParams().getP(), k.getParams().getG());
       }

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

    protected int engineGetKeySize(
        Key     key)
    {
        if (key instanceof RSAPrivateKey)
        {
            RSAPrivateKey   k = (RSAPrivateKey)key;

            return k.getModulus().bitLength();
        }
        else if (key instanceof RSAPublicKey)
        {
            RSAPublicKey   k = (RSAPublicKey)key;

            return k.getModulus().bitLength();
        }

        throw new IllegalArgumentException("not an RSA key!");
    }
View Full Code Here

            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());
       }
       else if (spec.isAssignableFrom(DHPrivateKeySpec.class) && key instanceof DHPrivateKey)
       {
           DHPrivateKey k = (DHPrivateKey)key;
          
           return new DHPrivateKeySpec(k.getX(), k.getParams().getP(), k.getParams().getG());
       }
       else if (spec.isAssignableFrom(DHPublicKeySpec.class) && key instanceof DHPublicKey)
       {
           DHPublicKey k = (DHPublicKey)key;
          
           return new DHPublicKeySpec(k.getY(), k.getParams().getP(), k.getParams().getG());
       }
       else if (spec.isAssignableFrom(java.security.spec.ECPublicKeySpec.class) && key instanceof ECPublicKey)
       {
           ECPublicKey k = (ECPublicKey)key;

           return new java.security.spec.ECPublicKeySpec(k.getW(), k.getParams());
       }
       else if (spec.isAssignableFrom(java.security.spec.ECPrivateKeySpec.class) && key instanceof ECPrivateKey)
       {
           ECPrivateKey k = (ECPrivateKey)key;

           return new java.security.spec.ECPrivateKeySpec(k.getS(), k.getParams());
       }

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

TOP

Related Classes of java.security.interfaces.RSAPrivateKey

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.