Java Key Create getKey()

Here you can find the source of getKey()

Description

Gets the key.

License

Open Source License

Exception

Parameter Description
GeneralSecurityException the general security exception

Return

the key

Declaration

protected static SecretKey getKey() throws GeneralSecurityException 

Method Source Code

//package com.java2s;
/*//from  ww  w .j  av  a2s. co m
 * Copyright: (c) 2004-2010 Mayo Foundation for Medical Education and 
 * Research (MFMER). All rights reserved. MAYO, MAYO CLINIC, and the
 * triple-shield Mayo logo are trademarks and service marks of MFMER.
 *
 * Except as contained in the copyright notice above, or as used to identify 
 * MFMER as the author of this software, the trade names, trademarks, service
 * marks, or product names of the copyright holder shall not be used in
 * advertising, promotion or otherwise in connection with this software without
 * prior written authorization of the copyright holder.
 * 
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 *       http://www.eclipse.org/legal/epl-v10.html
 * 
 */

import java.security.GeneralSecurityException;
import java.security.spec.KeySpec;

import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;

public class Main {
    /** Internal Key. */
    protected static char[] key = "MayoClinic".toCharArray();

    /**
     * Gets the key.
     * 
     * @return the key
     * 
     * @throws GeneralSecurityException the general security exception
     */
    protected static SecretKey getKey() throws GeneralSecurityException {
        KeySpec keySpec = new PBEKeySpec(key);
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        return keyFactory.generateSecret(keySpec);
    }
}

Related

  1. getKey()
  2. getKey()
  3. getKey(byte[] arrayBytesTemp)
  4. getKey(byte[] keyData)
  5. getKey(InputStream is)