Search the Community
Showing results for tags 'sha2'.
Found 1 result
-
This will work for any java program, you can use the following code to create a hash using any of the following cryptographic hash functions: MD2 MD5 Sha1 Sha-256 Sha-384 Sha-512 [code] import java.security.*; public static String createHash(String s) { try { MessageDigest md = MessageDigest.getInstance("Sha-512");//Change this to whatever Hash function you want to byte[] array = md.digest(s.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; i++) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3)); } return sb.toString(); } catch (NoSuchAlgorithmException e) { } return null; } [/code] There you go, secure hash for any string you want. Personally I use it to create a hash for the data I store on my MySQL Database, but there's multiple uses.
- 7 replies
-
- cryptography
- encrypt
-
(and 3 more)
Tagged with: