Package java.security.spec

Examples of java.security.spec.KeySpec


   *             fails
   */
  public SecurityEncryptionProvider(final String passPhrase) throws Exception {
    final SecretKeyFactory secretKeyFactory = SecretKeyFactory
        .getInstance(ALGORITHM);
    final KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(),
        SALT, ITERATION_COUNT, KEY_LENGTH);
    final SecretKey secretKeyTemp = secretKeyFactory
        .generateSecret(keySpec);
    this.secretKey = new SecretKeySpec(secretKeyTemp.getEncoded(),
        ALGORITHM_STANDARD);
View Full Code Here


    * @param publicKeyOpenSSH
    *           RSA public key in OpenSSH format
    * @return true if the keypairs match
    */
   public static boolean privateKeyMatchesPublicKey(String privateKeyPEM, String publicKeyOpenSSH) {
      KeySpec privateKeySpec = privateKeySpec(privateKeyPEM);
      checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec,
               "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec);
      return privateKeyMatchesPublicKey(RSAPrivateCrtKeySpec.class.cast(privateKeySpec),
               publicKeySpecFromOpenSSH(publicKeyOpenSSH));
   }
View Full Code Here

    * @param fingerprint
    *           ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9}
    * @return true if the keypair has the same fingerprint as supplied
    */
   public static boolean privateKeyHasFingerprint(String privateKeyPEM, String fingerprint) {
      KeySpec privateKeySpec = privateKeySpec(privateKeyPEM);
      checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec,
               "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec);
      return privateKeyHasFingerprint(RSAPrivateCrtKeySpec.class.cast(privateKeySpec), fingerprint);
   }
View Full Code Here

    * @param privateKeyPEM
    *           RSA private key in PEM format
    * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9}
    */
   public static String fingerprintPrivateKey(String privateKeyPEM) {
      KeySpec privateKeySpec = privateKeySpec(privateKeyPEM);
      checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec,
               "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec);
      RSAPrivateCrtKeySpec certKeySpec = RSAPrivateCrtKeySpec.class.cast(privateKeySpec);
      return fingerprint(certKeySpec.getPublicExponent(), certKeySpec.getModulus());
   }
View Full Code Here

    * @param sha1HexColonDelimited
    *           ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9}
    * @return true if the keypair has the same fingerprint as supplied
    */
   public static boolean privateKeyHasSha1(String privateKeyPEM, String sha1HexColonDelimited) {
      KeySpec privateKeySpec = privateKeySpec(privateKeyPEM);
      checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec,
               "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec);
      return privateKeyHasSha1(RSAPrivateCrtKeySpec.class.cast(privateKeySpec), sha1HexColonDelimited);
   }
View Full Code Here

    * @param privateKeyPEM
    *           RSA private key in PEM format
    * @return sha1HexColonDelimited ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9}
    */
   public static String sha1PrivateKey(String privateKeyPEM) {
      KeySpec privateKeySpec = privateKeySpec(privateKeyPEM);
      checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec,
               "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec);
      RSAPrivateCrtKeySpec certKeySpec = RSAPrivateCrtKeySpec.class.cast(privateKeySpec);
      return sha1(certKeySpec);
   }
View Full Code Here

  private void decryptAndVerify(Crypto crypto)
      throws InvalidKeySpecException, NoSuchAlgorithmException,
      NoSuchPaddingException, InvalidKeyException,
      IllegalBlockSizeException, BadPaddingException {
   
    KeySpec keySpec = Pems.privateKeySpec(PRIVATE_KEY);
    KeyFactory kf = crypto.rsaKeyFactory();
    PrivateKey privKey = kf.generatePrivate(keySpec);

    Cipher cipher = crypto.cipher("RSA");
    cipher.init(Cipher.DECRYPT_MODE, privKey);
View Full Code Here

        catch (Exception e)
        {
            fail("unexpected exception.", e);
        }
       
        KeySpec ks = null;
        SecretKey secKey = null;
        byte[] bb = new byte[24];

        try
        {
            skF.getKeySpec(null, null);
           
            fail("failed exception test - no exception thrown");
        }
        catch (InvalidKeySpecException e)
        {
            // ignore okay
        }
        catch (Exception e)
        {
            fail("failed exception test.", e);
        }
        try
        {
            ks = (KeySpec)new DESedeKeySpec(bb);
            skF.getKeySpec(null, ks.getClass());
           
            fail("failed exception test - no exception thrown");
        }
        catch (InvalidKeySpecException e)
        {
View Full Code Here

                  certsBeginIdx = certsEndIdx;
               }
            } while (certsBeginIdx != -1);

            // parse private key
            KeySpec keySpec = Pems.privateKeySpec(ByteSource.wrap(pemPrivateKey.getBytes(Charsets.UTF_8)));
            PrivateKey privateKey = crypto.rsaKeyFactory().generatePrivate(keySpec);

            // populate keystore with private key and certs
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            @SuppressWarnings("unchecked")
View Full Code Here

    if (saltValue == null || saltValue.length() == 0)
      throw new ManifoldCFException("Missing required SALT value");
   
    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    KeySpec keySpec = new PBEKeySpec(passCode.toCharArray(), saltValue.getBytes(), 1024, 128);
    SecretKey secretKey = factory.generateSecret(keySpec);

    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    SecretKeySpec key = new SecretKeySpec(secretKey.getEncoded(), "AES");
    IvParameterSpec parameterSpec = new IvParameterSpec(iv);
View Full Code Here

TOP

Related Classes of java.security.spec.KeySpec

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.