Java Key Create getKey(String siteSecret)

Here you can find the source of getKey(String siteSecret)

Description

get Key

License

BSD License

Declaration

private static SecretKeySpec getKey(String siteSecret) 

Method Source Code

//package com.java2s;
/*//  ww  w  .j av  a  2s. c o m
 * Copyright (c) 2002-2015, Google reCAPTCHA-java Authors
 *
 * This software is distributable under the BSD license. See the terms of the
 * BSD license in the documentation provided with this software.
 *
 * http://www.opensource.org/licenses/bsd-license.php
 */

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

import javax.crypto.spec.SecretKeySpec;

public class Main {
    private static SecretKeySpec getKey(String siteSecret) {
        try {
            byte[] key = siteSecret.getBytes("UTF-8");
            key = Arrays.copyOf(MessageDigest.getInstance("SHA")
                    .digest(key), 16);
            return new SecretKeySpec(key, "AES");
        } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getKey(KeyStore ks, String alias, String pass)
  2. getKey(Object obj)
  3. getKey(String keyString)
  4. getKey(String keyString)
  5. getKey(String salt, String password)
  6. getKeyedDigest(String strSrc, String key)
  7. getKeyExchangeCipher()
  8. getKeyFactory()
  9. getKeyFactory()