sha

When generating a SHA256 / 512 hash, is there a minimum 'safe' amount of data to hash?

本秂侑毒 提交于 2019-11-30 06:03:31
I have heard that when creating a hash, it's possible that if small files or amounts of data are used, the resulting hash is more likely to suffer from a collision. If that is true, is there a minimum "safe" amount of data that should be used to ensure this doesn't happen? I guess the question could also be phrased as: What is the smallest amount of data that can be safely and securely hashed? A hash function accepts inputs of arbitrary (or at least very high) length, and produces a fixed-length output. There are more possible inputs than possible outputs, so collisions must exist. The whole

Use SHA-512 and salt to hash an MD5 hashed password?

老子叫甜甜 提交于 2019-11-30 03:41:19
问题 I am working on a system that has been hashing user passwords with MD5 (no salt). I want to store the passwords more securely using SHA-512 and a salt. While this is easy enough to implement for future passwords, I'd like to also retrofit the existing MD5 hashed passwords, preferably without forcing all the users to change their passwords. My idea is to just use SHA-512 and and an appropriate salt to hash the existing MD5 hash. I can either then set some flag in the database that indicates

How does Git(Hub) handle possible collisions from short SHAs?

笑着哭i 提交于 2019-11-29 22:04:44
Both Git and GitHub display short versions of SHAs -- just the first 7 characters instead of all 40 -- and both Git and GitHub support taking these short SHAs as arguments. E.g. git show 962a9e8 E.g. https://github.com/joyent/node/commit/962a9e8 Given that the possibility space is now orders of magnitude lower, "just" 268 million , how do Git and GitHub protect against collisions here? And how do they handle them? These short forms are just to simplify visual recognition and to make your life easier . Git doesn't really truncate anything, internally everything will be handled with the complete

Java and Hash algorithm to compare files [closed]

怎甘沉沦 提交于 2019-11-29 21:35:15
问题 I have to fingerprint files to match doublets. What is recommended with Java in 2013? Should I also compare the file size, or is this a unnecessary check? The probability of false positive should be very close to 0 EDIT: Lots of answers, thanks. What is the standard of backup software today? SHA-256? higher? I guess md5 is not suitable? 回答1: If the probability of false positives has to be zero , as opposed to "lower than the probability you will be struck by lightning," then no hash algorithm

Creating signed URLs for Google Cloud Storage using NodeJS

人盡茶涼 提交于 2019-11-29 17:58:46
问题 I'm trying to create a signature for a privately stored file in Google Cloud Storage; so that I can distribute a time-limited link. Currently doing this and it makes a signature that's too short ... where am I going wrong? var crypto = require("crypto"); var ttl = new Date().getTime() + 3600; var id = 'the_target_file.txt'; var bucketName = 'bucket_name'; var POLICY_JSON = "GET\n" + "\n" + "\n" + ttl + "\n" + '/' + bucketName + '/' + id; // stringify and encode the policy var stringPolicy =

How much faster is the native implementation of the native cryptographic hashes on Windows than the .Net Managed version?

大憨熊 提交于 2019-11-29 13:57:03
问题 I'm providing hashes for sets of data in order to fingerprint the data and identify it by hash - this is the core use case for fast hashes like SHA1 and MD5. In .Net, there is an option to go with the native or managed implementations of some of these hashes (the SHA variants, anyway). I'm looking for an MD5 managed implementation, and there doesn't appear to be one in the .Net Framework, but wondered if the wrapped native CSP is faster anyway, and if I should just use it content that there

Convert Encrypt code in java to Ruby

*爱你&永不变心* 提交于 2019-11-29 10:25:12
问题 I have been trying to convert a code for encrypt in java to ruby, but I am not able to do it completely. I getting different values. passphrase = passphrase + STATIC_KEY; byte[] key = passphrase.getBytes("UTF-8"); MessageDigest sha = MessageDigest.getInstance("SHA-1"); key = sha.digest(key); key = Arrays.copyOf(key, 16); SecretKey secretKey = new SecretKeySpec(key, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec initialisationVector = new IvParameterSpec(

Is it okay to truncate a SHA256 hash to 128 bits?

故事扮演 提交于 2019-11-29 09:21:23
MD5 and SHA-1 hashes have weaknesses against collision attacks. SHA256 does not but it outputs 256 bits. Can I safely take the first or last 128 bits and use that as the hash? I know it will be weaker (because it has less bits) but otherwise will it work? Basically I want to use this to uniquely identify files in a file system that might one day contain a trillion files. I'm aware of the birthday problem and a 128 bit hash should yield about a 1 in a trillion chance on a trillion files that there would be two different files with the same hash. I can live with those odds. What I can't live

Converting a unique seed string into a random, yet deterministic, float value in Ruby

纵饮孤独 提交于 2019-11-29 09:16:06
I'm having a hard time with this, conceptually. Basically, I need to accept some arbitrary unique string, and be able to convert that to a normalized float value. What the output float value is doesn't really matter, so long as the same string input always results in the same normalized float output. So this is a hashing algorithm right? I'm familiar with SHA1 or MD5, and this seems similar to password hashing where the result is the same for the correct password. But those methods output strings of characters, I believe. And what I'm not getting is how I would turn the result of a SHA1 or MD5

JWT (JSON Web Token) in PHP without using 3rd-party library. How to sign?

家住魔仙堡 提交于 2019-11-29 07:53:18
问题 There are a few libraries for implementing JSON Web Tokens (JWT) in PHP, such as php-jwt. I am writing my own, very small and simple class but cannot figure out why my signature fails validation here even though I've tried to stick to the standard. I've been trying for hours and I'm stuck. Please help! My code is simple //build the headers $headers = ['alg'=>'HS256','typ'=>'JWT']; $headers_encoded = base64url_encode(json_encode($headers)); //build the payload $payload = ['sub'=>'1234567890',