Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static byte[] generateKey(String strSrc) { MessageDigest digest; byte[] keyBytes = new byte[32]; try { digest = MessageDigest.getInstance("SHA-256"); digest.update(strSrc.getBytes("UTF-8")); System.arraycopy(digest.digest(), 0, keyBytes, 0, keyBytes.length); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return keyBytes; } }