Package java.security.spec

Examples of java.security.spec.EncodedKeySpec


            LdapException ne = new LdapException( I18n.err( I18n.ERR_288, ALGORITHM ) );
            ne.initCause( e );
            throw ne;
        }

        EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec( entry.get( PRIVATE_KEY_AT ).getBytes() );
        try
        {
            privateKey = keyFactory.generatePrivate( privateKeySpec );
        }
        catch ( Exception e )
        {
            LdapException ne = new LdapException( I18n.err( I18n.ERR_289 ) );
            ne.initCause( 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


     * 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

     */
    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

     * 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

     * 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

     * 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

           privKeyIs.close();
           baos.close();
           byte[] privKeyByte = baos.toByteArray();
          // get the public key from bytes 
          KeyFactory keyFactory = KeyFactory.getInstance("DSA");
          EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privKeyByte);
          privKey = keyFactory.generatePrivate(privateKeySpec);
      } catch (IOException e) {
      SpagoBITracer.major("SPAGOBI",
                this.getClass().getName(),
                "getPrivateKeyDSA",
View Full Code Here

        publicKeyIs.close();
        baos.close();
        byte[] pubKeyByte = baos.toByteArray();
        // get the public key from bytes 
        KeyFactory keyFactory = KeyFactory.getInstance("DSA");
        EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(pubKeyByte);
        pubKey = keyFactory.generatePublic(publicKeySpec);
    }catch(DocumentException de){
      logger.error("Engines"+ this.getClass().getName()+ "getPublicKey:"+
             "Error during parsing of the security configuration file", de);
    } catch (IOException e) {
View Full Code Here

      return null;
    }
   
    try {
      KeyFactory fac = KeyFactory.getInstance("RSA");
      EncodedKeySpec spec = new X509EncodedKeySpec(publicKey);
      return fac.generatePublic(spec);
    }
    catch (NoSuchAlgorithmException e) {
      throw new IllegalStateException(e);
    }
View Full Code Here

      return null;
    }

    try {
      KeyFactory fac = KeyFactory.getInstance("RSA");
      EncodedKeySpec spec = new PKCS8EncodedKeySpec(privateKey);
      return fac.generatePrivate(spec);
    }
    catch (NoSuchAlgorithmException e) {
      throw new IllegalStateException(e);
    }
View Full Code Here

TOP

Related Classes of java.security.spec.EncodedKeySpec

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.