Code example for SecretKey

Methods: getEncoded

0
	 */ 
	public static String initMacKey() throws Exception {
		KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_MAC);
 
		SecretKey secretKey = keyGenerator.generateKey();
		return Base64Util.encryptBASE64(new String(secretKey.getEncoded()));
	} 
 
	/** 
	 * HMAC encrypt 
	 *  
	 * @param data 
	 * @param key 
	 * @return 
	 * @throws Exception 
	 */ 
	public static String encryptHMAC(String source, String key) throws Exception {
		byte[] data = source.getBytes();
		SecretKey secretKey = new SecretKeySpec(Base64Util.decryptBASE64(key)
				.getBytes(), KEY_MAC);
		Mac mac = Mac.getInstance(secretKey.getAlgorithm());