Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String shaHash(String input)
- throws NoSuchAlgorithmException {
- if (input == null) {
- return null;
- }
- MessageDigest sha = MessageDigest.getInstance("SHA");
- try {
- sha.update(input.getBytes("UTF8"));
- BigInteger hash = new BigInteger(1, sha.digest());
- return hash.toString(16);
- } catch (UnsupportedEncodingException e) {}
- return null;
- }
- StringBuilder convertedId = new StringBuilder();
- var idToByte = Encoding.ASCII.GetBytes(id);
- using (SHA1 sha1 = SHA1.Create())
- {
- var bytes = sha1.ComputeHash(idToByte);
- for (int i = 0; i < bytes.Length; i++)
- {
- convertedId.Append(bytes[i].ToString("x2"));
- }
- }
- return convertedId.ToString();
- StringBuilder convertedId = new StringBuilder();
- var idToByte = Encoding.ASCII.GetBytes(id);
- using (SHA1 sha1 = SHA1.Create())
- {
- var bytes = sha1.ComputeHash(idToByte);
- for (int i = 0; i < bytes.Length; i++)
- {
- if (i == 0 && bytes[i] < 16)
- convertedId.Append(bytes[i].ToString("x1"));
- else
- convertedId.Append(bytes[i].ToString("x2"));
- }
- }
- return convertedId.ToString();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement