Example usage for java.security InvalidKeyException printStackTrace

List of usage examples for java.security InvalidKeyException printStackTrace

Introduction

In this page you can find the example usage for java.security InvalidKeyException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.suren.autotest.web.framework.util.EncryptorUtil.java

/**
 * Base64??//from  ww  w .j  a  v  a 2s.  co m
 * @param base64Text
 * @return
 */
public static String decryptWithBase64(String base64Text) {
    byte[] encryptData = Base64.decodeBase64(base64Text);
    try {
        return Encryptor.getInstance(Encryptor.ALG_DES, getSecretKey()).decryptStr(encryptData);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (IllegalBlockSizeException e) {
        e.printStackTrace();
    } catch (BadPaddingException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
    }

    return base64Text;
}

From source file:org.gss_project.gss.web.client.TestClient.java

public static String sign(String httpMethod, String timestamp, String path, String token) {
    String input = httpMethod + timestamp + path;
    String signed = null;//  w  w  w .ja  v  a2  s  .c  o m

    try {
        System.err.println("Token:" + token);
        // Get an HMAC-SHA1 key from the authentication token.
        System.err.println("Input: " + input);
        SecretKeySpec signingKey = new SecretKeySpec(Base64.decodeBase64(token.getBytes()), "HmacSHA1");

        // Get an HMAC-SHA1 Mac instance and initialize with the signing key.
        Mac hmac = Mac.getInstance("HmacSHA1");
        hmac.init(signingKey);

        // Compute the HMAC on the input data bytes.
        byte[] rawMac = hmac.doFinal(input.getBytes());

        // Do base 64 encoding.
        signed = new String(Base64.encodeBase64(rawMac), "US-ASCII");

    } catch (InvalidKeyException ikex) {
        System.err.println("Fatal key exception: " + ikex.getMessage());
        ikex.printStackTrace();
    } catch (UnsupportedEncodingException ueex) {
        System.err.println("Fatal encoding exception: " + ueex.getMessage());
    } catch (NoSuchAlgorithmException nsaex) {
        System.err.println("Fatal algorithm exception: " + nsaex.getMessage());
        nsaex.printStackTrace();
    }

    if (signed == null)
        System.exit(-1);
    System.err.println("Signed: " + signed);
    return signed;
}

From source file:dimensionsorter.DimensionSorter.java

private static void initializeImageSorter() {
    try {// w w w  . j  av  a 2  s.  c  om
        // Retrieve storage account from connection-string
        // (The storage connection string needs to be changed in case of
        // cloud infrastructure
        // is used instead of emulator)
        CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);

        // Create the queue client
        CloudQueueClient queueClient = storageAccount.createCloudQueueClient();

        // Retrieve a reference to a queue
        CloudQueue queue = queueClient.getQueueReference(globalImageSorterQueue);

        // Create the queue if it doesn't already exist
        queue.createIfNotExist();

        // Create the json object with the appropriate variables
        JSONObject obj = new JSONObject();
        obj.put("dataset", datasetName);
        obj.put("numOfL", new Integer(numberOfImageSorterNodes));
        obj.put("numOfImages", new Integer(numOfImages));

        // Send the Message
        CloudQueueMessage message = new CloudQueueMessage(obj.toJSONString());
        queue.addMessage(message);

    } catch (InvalidKeyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (StorageException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:de.marius_oe.cfs.cryption.Crypter.java

/**
 * Returns the {@link Cipher} for the encryption and decryption process.
 * /*  w  ww  .j  a v  a 2 s  .c o m*/
 * @param mode
 *            {@link Cipher.DECRYPT_MODE} or {@link Cipher.ENCRYPT_MODE}
 * @param iv
 *            the initial vector which should be used in the cipher. if the
 *            iv is <code>null</code>, a new iv will be generated.
 * @return {@link Cipher} object
 */
private static Cipher getCipher(int mode, byte[] iv) {
    try {
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        if (iv == null) {
            cipher.init(mode, KeyManager.instance().getKey());
        } else {
            IvParameterSpec parameterSpec = new IvParameterSpec(iv);
            cipher.init(mode, KeyManager.instance().getKey(), parameterSpec);
        }
        return cipher;
    } catch (InvalidKeyException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } catch (InvalidAlgorithmParameterException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

From source file:org.mozilla.android.sync.Cryptographer.java

public static byte[] decrypt(CryptoInfo info) {

    // Check HMAC
    if (!verifyHmac(info)) {
        return null;
    }/*www  . j  av  a2s  .c  o m*/

    Cipher cipher = getCipher();
    try {
        cipher.init(Cipher.DECRYPT_MODE,
                new SecretKeySpec(info.getKeys().getEncryptionKey(), KEY_ALGORITHM_SPEC),
                new IvParameterSpec(info.getIv()));
    } catch (InvalidKeyException e) {
        e.printStackTrace();
        return null;
    } catch (InvalidAlgorithmParameterException e) {
        e.printStackTrace();
        return null;
    }

    return commonCrypto(cipher, info.getMessage());
}

From source file:org.mozilla.android.sync.Cryptographer.java

public static CryptoInfo encrypt(CryptoInfo info) {

    Cipher cipher = getCipher();//from   w w w .j av a2  s .com
    try {
        cipher.init(Cipher.ENCRYPT_MODE,
                new SecretKeySpec(info.getKeys().getEncryptionKey(), KEY_ALGORITHM_SPEC));
    } catch (InvalidKeyException e) {
        e.printStackTrace();
        return null;
    }

    // Encrypt
    byte[] encryptedBytes = commonCrypto(cipher, info.getMessage());
    info.setMessage(encryptedBytes);

    // Save IV
    info.setIv(cipher.getIV());

    // Generate HMAC
    info.setHmac(generateHmac(info));

    return info;

}

From source file:com.microsoft.windowsazure.management.compute.ComputeManagementIntegrationTestBase.java

protected static void cleanBlob(String storageAccountName, String storageContainer) {
    // Create the blob client
    MockCloudBlobClient blobClient = null;
    try {/*from w  w  w .  j  a  va 2 s  . com*/
        blobClient = createBlobClient(storageAccountName, storageAccountKey);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    if (blobClient != null) {
        MockCloudBlobContainer container = null;
        try {
            container = blobClient.getContainerReference(storageContainer);
        } catch (URISyntaxException e) {
        } catch (StorageException e) {
        }

        try {
            container.breakLease(0);
        } catch (StorageException e) {
        }

        try {
            container.delete();
        } catch (StorageException e) {
        }

        try {
            while (container.exists()) {
                Thread.sleep(1000);
            }
        } catch (StorageException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.aqnote.shared.cryptology.symmetric.AES.java

private static void generateCipher(String rawKey) {
    try {/*  w w w .ja  v  a  2  s .  c  o m*/
        SecretKeySpec keySpec = new SecretKeySpec(rawKey.getBytes(ENCODE_UTF_8), CIPHER_NAME);
        encodeCipher = Cipher.getInstance(CIPHER_NAME);
        encodeCipher.init(Cipher.ENCRYPT_MODE, keySpec);

        decodeCipher = Cipher.getInstance(CIPHER_NAME);
        byte iv[] = encodeCipher.getIV();
        IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
        decodeCipher.init(Cipher.DECRYPT_MODE, keySpec, ivParameterSpec);
    } catch (InvalidKeyException e) {
        throw new RuntimeException(e);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    } catch (NoSuchPaddingException e) {
        throw new RuntimeException(e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    } catch (InvalidAlgorithmParameterException e) {
        e.printStackTrace();
    }

}

From source file:org.toobsframework.util.Crypto.java

private void initEncryptCipher(Key key) {
    try {//from w  w  w.j a  v a2  s.  c  om
        encipher = Cipher.getInstance(ALGORITHM);
        encipher.init(Cipher.ENCRYPT_MODE, key);
    } catch (InvalidKeyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.toobsframework.util.Crypto.java

private void initDecryptCipher(Key key) {
    try {//from   w w  w. j  a v a  2s. c o  m
        decipher = Cipher.getInstance(ALGORITHM);
        decipher.init(Cipher.DECRYPT_MODE, key);
    } catch (InvalidKeyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchPaddingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}