change colorizing of fingerprint to use SHA1 based on apg's commit 67ffc24526

This commit is contained in:
uberspot
2014-03-12 18:48:17 +02:00
parent a9e5619a14
commit e909b6bb9d
2 changed files with 58 additions and 10 deletions

View File

@@ -17,6 +17,9 @@
package org.sufficientlysecure.keychain.helper;
import java.security.DigestException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import java.util.Set;
@@ -58,4 +61,23 @@ public class OtherHelper {
}
}
/**
* Converts the given bytes to a unique RGB color using SHA1 algorithm
* @param bytes
* @return an integer array containing 3 numeric color representations (Red, Green, Black)
* @throws NoSuchAlgorithmException
* @throws DigestException
*/
public static int[] getRgbForData(byte[] bytes) throws NoSuchAlgorithmException, DigestException {
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(bytes);
byte[] digest = md.digest();
int[] result = {((int) digest[0] + 256) % 256,
((int) digest[1] + 256) % 256,
((int) digest[2] + 256) % 256};
return result;
}
}