Java Key Create getKey(String keyString)

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

Description

get Key

License

Open Source License

Declaration

public static Key getKey(String keyString) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.util.*;
import java.io.*;

public class Main {
    public static Key getKey(String keyString) {
        try {//from   w w  w.j  a va 2 s.  c  o m
            byte[] bytes = getBytes(keyString);
            DESKeySpec pass = new DESKeySpec(bytes);
            SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
            SecretKey s = skf.generateSecret(pass);
            return s;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private static byte[] getBytes(String str) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        StringTokenizer st = new StringTokenizer(str, "-", false);
        while (st.hasMoreTokens()) {
            int i = Integer.parseInt(st.nextToken());
            bos.write((byte) i);
        }
        return bos.toByteArray();
    }
}

Related

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