Example usage for java.security NoSuchAlgorithmException getLocalizedMessage

List of usage examples for java.security NoSuchAlgorithmException getLocalizedMessage

Introduction

In this page you can find the example usage for java.security NoSuchAlgorithmException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.apache.xml.security.algorithms.implementations.SignatureDSA.java

/**
 * Constructor SignatureDSA/*from w  w  w. java2 s  .  com*/
 *
 * @throws XMLSignatureException
 */
public SignatureDSA() throws XMLSignatureException {
    String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA.URI);
    if (log.isDebugEnabled()) {
        log.debug("Created SignatureDSA using " + algorithmID);
    }

    String provider = JCEMapper.getProviderId();
    try {
        if (provider == null) {
            this.signatureAlgorithm = Signature.getInstance(algorithmID);
        } else {
            this.signatureAlgorithm = Signature.getInstance(algorithmID, provider);
        }
    } catch (java.security.NoSuchAlgorithmException ex) {
        Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
        throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
    } catch (java.security.NoSuchProviderException ex) {
        Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
        throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
    }
}

From source file:com.qut.middleware.esoemanager.manager.logic.impl.ServiceCryptoImpl.java

private String generatePassphrase() {
    SecureRandom random;// ww  w .  j  a v a  2s  .  c o m
    String passphrase;
    byte[] buf;

    try {
        random = SecureRandom.getInstance("SHA1PRNG");
    } catch (NoSuchAlgorithmException nsae) {
        this.logger.error("NoSuchAlgorithmException when trying to create SecureRandom instance " //$NON-NLS-1$
                + nsae.getLocalizedMessage());
        this.logger.debug(nsae.getLocalizedMessage(), nsae);
        random = new SecureRandom();
    }

    buf = new byte[Constants.PASSPHRASE_LENGTH];
    random.nextBytes(buf);
    passphrase = new String(Hex.encodeHex(buf));

    return passphrase;
}

From source file:org.apache.xml.security.algorithms.implementations.SignatureECDSA.java

/**
 * Constructor SignatureRSA//  w  w  w.  j av a2 s  .  co m
 *
 * @throws XMLSignatureException
 */
public SignatureECDSA() throws XMLSignatureException {

    String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());

    if (log.isDebugEnabled()) {
        log.debug("Created SignatureECDSA using " + algorithmID);
    }
    String provider = JCEMapper.getProviderId();
    try {
        if (provider == null) {
            this.signatureAlgorithm = Signature.getInstance(algorithmID);
        } else {
            this.signatureAlgorithm = Signature.getInstance(algorithmID, provider);
        }
    } catch (java.security.NoSuchAlgorithmException ex) {
        Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };

        throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
    } catch (NoSuchProviderException ex) {
        Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };

        throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
    }
}

From source file:jfs.sync.encryption.AbstractEncryptedStorageAccess.java

protected String getEncryptedFileName(String relativePath, String pathElement) {
    if (encryptionCache.containsKey(relativePath+getSeparator()+pathElement)) {
        return encryptionCache.get(relativePath+getSeparator()+pathElement);
    } // if//from w ww  . ja  v  a2s.c o  m
    try {
        Cipher encrypter = SecurityUtils.getCipher(getCipherSpec(), Cipher.ENCRYPT_MODE, getCredentials(relativePath));
        byte[] bytes = encrypter.doFinal(getEncodedFileName(relativePath, pathElement));
        StringBuilder result = new StringBuilder();
        int index = 0;
        int bc = 0;
        // System.out.print("E: ");
        for (int i = 0; i<bytes.length; i++) {
            for (int mask = 128; mask>0; mask = mask>>1) {
                int bit = ((bytes[i]&mask)==0) ? 0 : 1;
                // System.out.print(bit);
                index = (index<<1)+bit;
                bc++;
                if (bc==bits) {
                    char code = CODES[index];
                    result.append(code);
                    bc = 0;
                    index = 0;
                } // if
            } // for
            // System.out.print(" "+bytes[i]+" ");
        } // for
        index = index<<(bits-bc);
        char code = CODES[index];
        result.append(code);
        String resultString = result.toString();
        // System.out.println("");
        encryptionCache.put(relativePath+getSeparator()+pathElement, resultString);
        pathElement = resultString;
    } catch (NoSuchAlgorithmException nsae) {
        LOG.error("getEncryptedFileName() No Such Algorhithm "+nsae.getLocalizedMessage());
    } catch (NoSuchPaddingException nspe) {
        LOG.error("getEncryptedFileName() No Such Padding "+nspe.getLocalizedMessage());
    } catch (InvalidKeyException ike) {
        LOG.error("getEncryptedFileName() Invalid Key "+ike.getLocalizedMessage());
    } catch (ArrayIndexOutOfBoundsException e) {
        LOG.error("getEncryptedFileName("+pathElement+") ArrayIndexOutOfBoundsException", e);
    } catch (IllegalBlockSizeException e) {
        LOG.error("getEncryptedFileName("+pathElement+") IllegalBlockSizeException", e);
    } catch (BadPaddingException e) {
        LOG.error("getEncryptedFileName("+pathElement+") BadPaddingException", e);
    } // try/catch
    return pathElement;
}

From source file:org.apache.xml.security.algorithms.implementations.IntegrityHmac.java

/**
 * Method IntegrityHmac// w w w.j a v  a  2  s.  c o m
 *
 * @throws XMLSignatureException
 */
public IntegrityHmac() throws XMLSignatureException {
    String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
    if (log.isDebugEnabled()) {
        log.debug("Created IntegrityHmacSHA1 using " + algorithmID);
    }

    try {
        this.macAlgorithm = Mac.getInstance(algorithmID);
    } catch (java.security.NoSuchAlgorithmException ex) {
        Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };

        throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
    }
}

From source file:jfs.sync.encryption.AbstractEncryptedStorageAccess.java

protected String getDecryptedFileName(String relativePath, String name) {
    if (decryptionCache.containsKey(relativePath+getSeparator()+name)) {
        return decryptionCache.get(relativePath+getSeparator()+name);
    } // if//from  w w  w. j  ava2  s .  c o  m
    try {
        List<Byte> resultList = new ArrayList<Byte>();

        // System.out.print("D: ");
        int bc = 0;
        byte value = 0;
        for (int i = 0; i<name.length(); i++) {
            char code = name.charAt(i);
            byte index = reverseCodes[code];
            for (int mask = decoding_mask; mask>0; mask = mask>>1) {
                int bit = (index&mask)==0 ? 0 : 1;
                // System.out.print(bit);
                value = (byte) ((value<<1)+bit);
                bc++;
                if (bc==8) {
                    // System.out.print(" "+value+" ");
                    resultList.add(value);
                    bc = 0;
                    value = 0;
                } // if
            } // for
        } // for

        byte[] decodedBytes = new byte[resultList.size()];
        int i = 0;
        for (byte b : resultList) {
            decodedBytes[i++] = b;
        } // for

        // System.out.println("");

        Cipher decrypter = SecurityUtils.getCipher(getCipherSpec(), Cipher.DECRYPT_MODE, getCredentials(relativePath));
        byte[] decryptedBytes = decrypter.doFinal(decodedBytes);
        // name = new String(decryptedBytes, "UTF-8");
        String decryptedName = getDecodedFileName(relativePath, decryptedBytes);
        decryptionCache.put(relativePath+getSeparator()+name, decryptedName);
        name = decryptedName;
    } catch (NoSuchAlgorithmException nsae) {
        LOG.error("getDecryptedFileName() No Such Algorhithm "+nsae.getLocalizedMessage());
    } catch (NoSuchPaddingException nspe) {
        LOG.error("getDecryptedFileName() No Such Padding "+nspe.getLocalizedMessage());
    } catch (InvalidKeyException ike) {
        LOG.error("getDecryptedFileName() Invalid Key "+ike.getLocalizedMessage());
    } catch (ArrayIndexOutOfBoundsException e) {
        LOG.error("getDecryptedFileName() ArrayIndexOutOfBoundsException", e);
    } catch (IllegalBlockSizeException e) {
        LOG.error("getDecryptedFileName() IllegalBlockSizeException", e);
    } catch (BadPaddingException e) {
        LOG.error("getDecryptedFileName() BadPaddingException", e);
    } // try/catch
    return name;
}

From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java

public KeyPair generateKeyPair() throws CryptoException {
    try {//from  w  w w .  ja  v  a 2  s  .c  o m
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(this.keySize);

        KeyPair keyPair = keyGen.generateKeyPair();
        return keyPair;
    } catch (NoSuchAlgorithmException e) {
        this.logger.error("NoSuchAlgorithmException thrown, " + e.getLocalizedMessage());
        this.logger.debug(e.toString());
        throw new CryptoException(e.getLocalizedMessage(), e);
    }
}

From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java

public KeyStore addKeyPair(KeyStore keyStore, String keyStorePassphrase, KeyPair keyPair, String keyPairName,
        String keyPairPassphrase, String keyPairSubjectDN) throws CryptoException {
    logger.debug("Adding key pair to existing key store");

    try {//  w  w  w .  j ava  2 s . c  om
        // Create the public key certificate for storage in the key store.
        X509Certificate cert = generateV3Certificate(keyPair, keyPairSubjectDN);
        X500PrivateCredential privateCredentials = new X500PrivateCredential(cert, keyPair.getPrivate(),
                keyPairName);

        Certificate[] certChain = new X509Certificate[1];
        certChain[0] = privateCredentials.getCertificate();

        // Load our generated key store up. They all have the same password, which we set.
        keyStore.load(null, keyStorePassphrase.toCharArray());

        /* Add certificate which contains the public key and set the private key as a key entry in the key store */
        keyStore.setCertificateEntry(privateCredentials.getAlias(), privateCredentials.getCertificate());
        keyStore.setKeyEntry(privateCredentials.getAlias(), keyPair.getPrivate(),
                keyPairPassphrase.toCharArray(), certChain);

        return keyStore;
    } catch (NoSuchAlgorithmException e) {
        this.logger.error("NoSuchAlgorithmException thrown, " + e.getLocalizedMessage());
        this.logger.debug(e.toString());
        throw new CryptoException(e.getLocalizedMessage(), e);
    } catch (CertificateException e) {
        this.logger.error("CertificateException thrown, " + e.getLocalizedMessage());
        this.logger.debug(e.toString());
        throw new CryptoException(e.getLocalizedMessage(), e);
    } catch (KeyStoreException e) {
        this.logger.error("KeyStoreException thrown, " + e.getLocalizedMessage());
        this.logger.debug(e.toString());
        throw new CryptoException(e.getLocalizedMessage(), e);
    } catch (IOException e) {
        this.logger.error("IOException thrown, " + e.getLocalizedMessage());
        this.logger.debug(e.toString());
        throw new CryptoException(e.getLocalizedMessage(), e);
    }
}

From source file:staging.plugin.StagingUtils.java

/**
 * @param sourceFileStore//from w  ww.jav  a 2s  .co m
 * @param sourceFileInfo
 * @param checksumMonitor
 * @return
 * @throws CoreException
 */
private static String checksumWithMD5Digest(IFileStore source, IFileInfo sourceInfo, IProgressMonitor monitor)
        throws CoreException {
    // TODO honor cancellation requests during copy
    // TODO report progress
    log.info("source: {}", source);
    String result = null;
    byte[] buffer = new byte[chunkSize];
    int length = (int) sourceInfo.getLength();
    int progressTickBytes = length / 100;
    int bytesRead = 0;
    int totalBytesCopied = 0;
    InputStream in = null;
    try {
        MessageDigest messageDigest;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            throw new CoreException(new Status(Status.ERROR, StagingPlugin.PLUGIN_ID,
                    "Cannot compare checksums without MD5 algorithm.", e));
        }
        messageDigest.reset();
        in = new BufferedInputStream(source.openInputStream(EFS.NONE, null), 1024 * 64);
        while ((bytesRead = in.read(buffer, 0, chunkSize)) != -1) {
            messageDigest.update(buffer, 0, bytesRead);
            totalBytesCopied = totalBytesCopied + bytesRead;
            if (totalBytesCopied > 0 && progressTickBytes > 0) {
                if ((totalBytesCopied % progressTickBytes) < bytesRead) {
                    monitor.worked(1);
                    // if (length > 0) {
                    // int percent = (int) (100.0 * ((float)
                    // totalBytesCopied / length));
                    // monitor.subTask(percent + "% (" + totalBytesCopied /
                    // 1024 + "/" + length / 1024 + "K)");
                    // }
                }
            }
        }
        Hex hex = new Hex();
        result = new String(hex.encode(messageDigest.digest()));
    } catch (IOException e) {
        throw new CoreException(new Status(Status.ERROR, StagingPlugin.PLUGIN_ID, e.getLocalizedMessage(), e));
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            log.error("Trouble closing i/o resources", e);
        }
    }
    return result;
}

From source file:com.qut.middleware.deployer.logic.RegisterESOELogic.java

private String generatePassphrase() {
    SecureRandom random;//  w ww.  j a  v  a 2s.c  o  m
    String passphrase;
    byte[] buf;

    try {
        /* Attempt to get the specified RNG instance */
        random = SecureRandom.getInstance("SHA1PRNG");
    } catch (NoSuchAlgorithmException nsae) {
        this.logger.error("NoSuchAlgorithmException when trying to create SecureRandom instance " //$NON-NLS-1$
                + nsae.getLocalizedMessage());
        this.logger.debug(nsae.getLocalizedMessage(), nsae);
        random = new SecureRandom();
    }

    buf = new byte[Constants.PASSPHRASE_LENGTH];
    random.nextBytes(buf);
    passphrase = new String(Hex.encodeHex(buf));

    return passphrase;
}