Compute SHA-1 of byte array

What about: import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Formatter; public static String SHAsum(byte[] convertme) throws NoSuchAlgorithmException{ MessageDigest md = MessageDigest.getInstance(“SHA-1”); return byteArray2Hex(md.digest(convertme)); } private static String byteArray2Hex(final byte[] hash) { Formatter formatter = new Formatter(); for (byte b : hash) { formatter.format(“%02x”, b); } return formatter.toString(); }

How do you verify an RSA SHA1 signature in Python?

Use M2Crypto. Here’s how to verify for RSA and any other algorithm supported by OpenSSL: pem = “””—–BEGIN PUBLIC KEY—– MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfG4IuFO2h/LdDNmonwGNw5srW nUEWzoBrPRF1NM8LqpOMD45FAPtZ1NmPtHGo0BAS1UsyJEGXx0NPJ8Gw1z+huLrl XnAVX5B4ec6cJfKKmpL/l94WhP2v8F3OGWrnaEX1mLMoxe124Pcfamt0SPCGkeal VvXw13PLINE/YptjkQIDAQAB —–END PUBLIC KEY—–“”” # your example key from M2Crypto import BIO, RSA, EVP bio = BIO.MemoryBuffer(pem) rsa = RSA.load_pub_key_bio(bio) pubkey = EVP.PKey() pubkey.assign_rsa(rsa) # if you need a different digest than … Read more

Is it possible to reverse a SHA-1 hash?

No, you cannot reverse SHA-1, that is exactly why it is called a Secure Hash Algorithm. What you should definitely be doing though, is include the message that is being transmitted into the hash calculation. Otherwise a man-in-the-middle could intercept the message, and use the signature (which only contains the sender’s key and the timestamp) … Read more

Objective C: SHA1

CommonCrypto (an Apple framework) has functions for calculating SHA-1 hashes, including a one-step hash: #include <CommonCrypto/CommonDigest.h> unsigned char digest[CC_SHA1_DIGEST_LENGTH]; NSData *stringBytes = [someString dataUsingEncoding: NSUTF8StringEncoding]; /* or some other encoding */ if (CC_SHA1([stringBytes bytes], [stringBytes length], digest)) { /* SHA-1 hash has been calculated and stored in ‘digest’. */ … } For a set of … Read more

Simple (non-secure) hash function for JavaScript? [duplicate]

I didn’t verify this myself, but you can look at this JavaScript implementation of Java’s String.hashCode() method. Seems reasonably short. With this prototype you can simply call .hashCode() on any string, e.g. “some string”.hashCode(), and receive a numerical hash code (more specifically, a Java equivalent) such as 1395333309. String.prototype.hashCode = function() { var hash = … Read more