Examples of EncodedKeySpec


Examples of java.security.spec.EncodedKeySpec

   * Returns a private key to be used with the oAuthHelper class.
   * @return the private key to use with the oAuthHelper class.
   */
  private PrivateKey getPrivateKey() {
    KeyFactory fac;
    EncodedKeySpec privKeySpec;
    PrivateKey privateKey = null;
    try {
      fac = KeyFactory.getInstance("RSA");
      privKeySpec = new PKCS8EncodedKeySpec(Base64.decode(getRsaKey()));
      privateKey = fac.generatePrivate(privKeySpec);
View Full Code Here

Examples of java.security.spec.EncodedKeySpec

            NamingException ne = new NamingException( "Failed to get key factory for algorithm: " + ALGORITHM );
            ne.setRootCause( e );
            throw ne;
        }
       
        EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec( entry.get( PRIVATE_KEY_AT ).getBytes() );
        try
        {
            privateKey = keyFactory.generatePrivate( privateKeySpec );
        }
        catch ( Exception e )
        {
            NamingException ne = new NamingException( "Bad private key format." );
            ne.setRootCause( e );
            throw ne;
        }
   
        EncodedKeySpec publicKeySpec = new X509EncodedKeySpec( entry.get( PUBLIC_KEY_AT ).getBytes() );
        try
        {
            publicKey = keyFactory.generatePublic( publicKeySpec );
        }
        catch ( InvalidKeySpecException e )
View Full Code Here

Examples of java.security.spec.EncodedKeySpec

     * object using valid parameter
     */
    public final void testPKCS8EncodedKeySpec() {
        byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4};
       
        EncodedKeySpec eks = new PKCS8EncodedKeySpec(encodedKey);
       
        assertTrue(eks instanceof PKCS8EncodedKeySpec);
    }
View Full Code Here

Examples of java.security.spec.EncodedKeySpec

     * object using valid parameter
     */
    public final void testX509EncodedKeySpec() {
        byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4};
       
        EncodedKeySpec eks = new X509EncodedKeySpec(encodedKey);
       
        assertTrue(eks instanceof X509EncodedKeySpec);
    }
View Full Code Here

Examples of java.security.spec.EncodedKeySpec

     * returns valid byte array
     */
    public final void testGetEncoded() {
       
        byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4};
        EncodedKeySpec meks = new MyEncodedKeySpec(encodedKey);
       
        /* Get encoded key */
        byte[] ek = meks.getEncoded();
       
        /* Check returned array */
        boolean result = true;
        for (int i=0; i<encodedKey.length; i++) {
            if (encodedKey[i] != ek[i]) {
View Full Code Here

Examples of java.security.spec.EncodedKeySpec

     */
    public final void testIsStatePreserved1() {
        /* Create initial byte array */
        byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4};
       
        EncodedKeySpec meks = new MyEncodedKeySpec(encodedKey);
       
        /* Modify initial array's value */
        encodedKey[3] = (byte)5;
       
        /* Get encoded key */
        byte[] ek = meks.getEncoded();
       
        /* Check that byte value has not been changed */
        assertTrue(ek[3] == (byte)4);
    }
View Full Code Here

Examples of java.security.spec.EncodedKeySpec

     * of <code>getEncoded()</code> method
    */
    public final void testIsStatePreserved2() {
       
        byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4};
        EncodedKeySpec meks = new MyEncodedKeySpec(encodedKey);
       
        /* Get encoded key */
        byte[] ek = meks.getEncoded();       
        /* Modify returned value */
        ek[3] = (byte)5;
        /* Get encoded key again */
        byte[] ek1 = meks.getEncoded();
       
        /* Check that byte value has not been changed */
        assertTrue(ek1[3] == (byte)4);
    }
View Full Code Here

Examples of java.security.spec.EncodedKeySpec

  }

  private PublicKey generatePublicKey() throws Base64DecodingException,
      NoSuchAlgorithmException, InvalidKeySpecException {
    byte[] publicByte = Base64.decode(keyValue);
    EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicByte);

    KeyFactory keyFactory = KeyFactory.getInstance(idAlg);

    return keyFactory.generatePublic(publicKeySpec);
  }
View Full Code Here

Examples of java.security.spec.EncodedKeySpec

  }

  private PrivateKey generatePrivateKey() throws Base64DecodingException,
      NoSuchAlgorithmException, InvalidKeySpecException {
    byte[] privateByte = Base64.decode(keyValue);
    EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateByte);

    KeyFactory keyFactory = KeyFactory.getInstance(idAlg);

    return keyFactory.generatePrivate(privateKeySpec);
  }
View Full Code Here

Examples of java.security.spec.EncodedKeySpec

            keyFactory = KeyFactory.getInstance(KEY_TYPE);
        } catch (final NoSuchAlgorithmException nsae) {
            throw new IllegalStateException(nsae);
        }

        final EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decodedPrivateKey);

        final RSAPrivateKey rsaPrivateKey;
        try {
            rsaPrivateKey = (RSAPrivateKey) keyFactory.generatePrivate(keySpec);
        } catch (final InvalidKeySpecException ikse) {
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.