Package java.security

Examples of java.security.UnrecoverableKeyException


   * @tests java.security.UnrecoverableKeyException#UnrecoverableKeyException(java.lang.String)
   */
  public void test_ConstructorLjava_lang_String() {
    // Test for method
    // java.security.UnrecoverableKeyException(java.lang.String)
    UnrecoverableKeyException e = new UnrecoverableKeyException(
        "test message");
    assertEquals("Failed toString test for constructed instance",
        "java.security.UnrecoverableKeyException: test message", e
            .toString());
  }
View Full Code Here


    /**
     * Test for <code>UnrecoverableKeyException()</code> constructor
     * Assertion: constructs UnrecoverableKeyException with no detail message
     */
    public void testUnrecoverableKeyException01() {
        UnrecoverableKeyException tE = new UnrecoverableKeyException();
        assertNull("getMessage() must return null.", tE.getMessage());
        assertNull("getCause() must return null", tE.getCause());
    }
View Full Code Here

     * Test for <code>UnrecoverableKeyException(String)</code> constructor
     * Assertion: constructs UnrecoverableKeyException with detail message msg.
     * Parameter <code>msg</code> is not null.
     */
    public void testUnrecoverableKeyException02() {
        UnrecoverableKeyException tE;
        for (int i = 0; i < msgs.length; i++) {
            tE = new UnrecoverableKeyException(msgs[i]);
            assertEquals("getMessage() must return: ".concat(msgs[i]), tE
                    .getMessage(), msgs[i]);
            assertNull("getCause() must return null", tE.getCause());
        }
    }
View Full Code Here

     * Assertion: constructs UnrecoverableKeyException when <code>msg</code>
     * is null
     */
    public void testUnrecoverableKeyException03() {
        String msg = null;
        UnrecoverableKeyException tE = new UnrecoverableKeyException(msg);
        assertNull("getMessage() must return null.", tE.getMessage());
        assertNull("getCause() must return null", tE.getCause());
    }
View Full Code Here

    public static String[] msgs = {
            "New message",
            "Long message for Exception. Long message for Exception. Long message for Exception." };

    protected Object[] getData() {
        return new Object[] { new UnrecoverableKeyException(),
                new UnrecoverableKeyException(null),
                new UnrecoverableKeyException(msgs[1]) };
    }
View Full Code Here

         KeyElement keyElement = new KeyElement(this.getKeyEntryElement(alias),
                                                this._baseURI);

         return keyElement.unwrap(password);
      } catch (XMLSecurityException ex) {
         throw new UnrecoverableKeyException(ex.getMessage());
      }
   }
View Full Code Here

      name = aid.getAlgorithmOID().toString();
      kf = KeyFactory.getInstance(name);

      return kf.generatePrivate(kspec);
  } catch (ASN1Exception e) {
      throw new UnrecoverableKeyException(e.getMessage());
  } catch (IOException e) {
      throw new InconsistentStateException("Caught IOException!");
  }
    }
View Full Code Here

            byte[] encrBytes = ((PrivateKeyEntry)entry).protectedKey;
            EncryptedPrivateKeyInfo encrInfo;
            try {
                encrInfo = new EncryptedPrivateKeyInfo(encrBytes);
            } catch (IOException ioe) {
                throw new UnrecoverableKeyException("Private key not stored "
                                                    + "as PKCS #8 " +
                                                    "EncryptedPrivateKeyInfo");
            }
            key = keyProtector.recover(encrInfo);
        } else {
View Full Code Here

        try {
            String encrAlg = encrInfo.getAlgorithm().getOID().toString();
            if (!encrAlg.equals(PBE_WITH_MD5_AND_DES3_CBC_OID)
                && !encrAlg.equals(KEY_PROTECTOR_OID)) {
                throw new UnrecoverableKeyException("Unsupported encryption "
                                                    + "algorithm");
            }

            if (encrAlg.equals(KEY_PROTECTOR_OID)) {
                // JDK 1.2 style recovery
                plain = recover(encrInfo.getEncryptedData());
            } else {
                byte[] encodedParams =
                    encrInfo.getAlgorithm().getEncodedParams();

                // parse the PBE parameters into the corresponding spec
                AlgorithmParameters pbeParams =
                    AlgorithmParameters.getInstance("PBE");
                pbeParams.init(encodedParams);
                PBEParameterSpec pbeSpec = (PBEParameterSpec)
                    pbeParams.getParameterSpec(PBEParameterSpec.class);

                // create PBE key from password
                PBEKeySpec pbeKeySpec = new PBEKeySpec(this.password);
                SecretKey sKey =
                    new PBEKey(pbeKeySpec, "PBEWithMD5AndTripleDES");
                pbeKeySpec.clearPassword();

                // decrypt private key
                PBEWithMD5AndTripleDESCipher cipher;
                cipher = new PBEWithMD5AndTripleDESCipher();
                cipher.engineInit(Cipher.DECRYPT_MODE, sKey, pbeSpec, null);
                plain=cipher.engineDoFinal(encrInfo.getEncryptedData(), 0,
                                           encrInfo.getEncryptedData().length);
            }

            // determine the private-key algorithm, and parse private key
            // using the appropriate key factory
            String oidName = new AlgorithmId
                (new PrivateKeyInfo(plain).getAlgorithm().getOID()).getName();
            KeyFactory kFac = KeyFactory.getInstance(oidName);
            return kFac.generatePrivate(new PKCS8EncodedKeySpec(plain));

        } catch (NoSuchAlgorithmException ex) {
            // Note: this catch needed to be here because of the
            // later catch of GeneralSecurityException
            throw ex;
        } catch (IOException ioe) {
            throw new UnrecoverableKeyException(ioe.getMessage());
        } catch (GeneralSecurityException gse) {
            throw new UnrecoverableKeyException(gse.getMessage());
        }
    }
View Full Code Here

        md.update(plainKey);
        digest = md.digest();
        md.reset();
        for (i = 0; i < digest.length; i++) {
            if (digest[i] != protectedKey[SALT_LEN + encrKeyLen + i]) {
                throw new UnrecoverableKeyException("Cannot recover key");
            }
        }
        return plainKey;
    }
View Full Code Here

TOP

Related Classes of java.security.UnrecoverableKeyException

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.