sha256

SHA-256 or MD5 for file integrity

ぃ、小莉子 提交于 2019-11-27 10:15:53
问题 I know that SHA-256 is favored over MD5 for security, etc., but, if I am to use a method to only check file integrity (that is, nothing to do with password encryption, etc.), is there any advantage of using SHA-256? Since MD5 is 128-bit and SHA-256 is 256-bit (therefore twice as big)... Would it take up to twice as long to encrypt? Where time is not of essence, like in a backup program, and file integrity is all that is needed, would anyone argue against MD5 for a different algorithm, or even

Digital signature in c# without using BouncyCastle

人盡茶涼 提交于 2019-11-27 09:51:39
Without using 3rd party BouncyCastle library, is there a way to read a custom private key and sign the message ? (sha256 hash+encryption using private key) Technically, yes. Depending on what kind of key you have the answer gets more tricky. PKCS#8 PrivateKeyInfo (PEM "BEGIN PRIVATE KEY") If you have this type of file, and you're on .NET 4.6 or higher, then yes. You need to have the DER encoded (vs PEM encoded) data blob (see below if it's PEM). using (CngKey key = CngKey.Import(blob, CngKeyBlobFormat.Pkcs8PrivateBlob)) using (RSA rsa = new RSACng(key)) { return rsa.SignData(data,

Java SHA256 outputs different hash to PHP SHA256?

筅森魡賤 提交于 2019-11-27 08:29:36
PHP code: echo hash('sha256', 'jake'); PHP output: cdf30c6b345276278bedc7bcedd9d5582f5b8e0c1dd858f46ef4ea231f92731d Java code: String s = "jake"; MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(s.getBytes(Charset.forName("UTF-8"))); byte[] hashed = md.digest(); String s2 = ""; for (byte b : hashed) { s2 += b; } System.out.println(s2); Java output: -51-1312107528211839-117-19-57-68-19-39-43884791-1141229-4088-12110-12-223531-11011529 I had expected the two to return the same result. Obviously, this is not the case. How can I get the two to match up or is it impossible? EDIT:

Calculating a SHA hash with a string + secret key in python

一个人想着一个人 提交于 2019-11-27 06:20:47
Amazon Product API now requires a signature with every request which I'm trying to generate ushing Python. The step I get hung up on is this one: "Calculate an RFC 2104-compliant HMAC with the SHA256 hash algorithm using the string above with our "dummy" Secret Access Key: 1234567890. For more information about this step, see documentation and code samples for your programming language." Given a string and a secret key (in this case 1234567890) how do I calculate this hash using Python? ----------- UPDATE ------------- The first solution using HMAC.new looks correct however I'm getting a

Hashing a string with Sha256

天涯浪子 提交于 2019-11-27 05:54:43
I try to hash a string using SHA256, I'm using the following code: using System; using System.Security.Cryptography; using System.Text; public class Hash { public static string getHashSha256(string text) { byte[] bytes = Encoding.Unicode.GetBytes(text); SHA256Managed hashstring = new SHA256Managed(); byte[] hash = hashstring.ComputeHash(bytes); string hashString = string.Empty; foreach (byte x in hash) { hashString += String.Format("{0:x2}", x); } return hashString; } } However, this code gives significantly different results compared to my friends php, as well as online generators (such as

Sha256 in Objective-C for iPhone

蓝咒 提交于 2019-11-27 05:29:43
问题 When I use this code to create a sha256 of a string unsigned char hashedChars[32]; NSString *inputString; inputString = [NSString stringWithFormat:@"hello"]; NSData * inputData = [inputString dataUsingEncoding:NSUTF8StringEncoding]; CC_SHA256(inputData.bytes, inputData.length, hashedChars); It returns the hash correctly, but I need to insert a string like this \x00\x25\x53 and in this case, the function returns a sha256 of empty string because the specified encoding cannot be used to convert

Java openssl encryption / decryption key generation [duplicate]

旧巷老猫 提交于 2019-11-27 05:13:26
This question already has an answer here: How to decrypt file in Java encrypted with openssl command using AES? 3 answers AES 256 Encryption Issue 1 answer I'm using Java 8 and I'm attempting to emulate the following openssl calls with Java. Encrypt: echo -n 'hello world' | openssl enc -a -aes-256-cbc -md sha256 -pass pass:97DE:4F76 U2FsdGVkX18PnO/NLSxJ1pg6OKoLyZApMz7aBRfKhJc= Decrypt: echo U2FsdGVkX18PnO/NLSxJ1pg6OKoLyZApMz7aBRfKhJc= | openssl enc -d -a -aes-256-cbc -md sha256 -pass pass:97DE:4F76 hello world Questions: My implementation doesn't work. I've visited many other StackOverflow

Best practice for hashing passwords - SHA256 or SHA512?

天涯浪子 提交于 2019-11-27 02:04:24
问题 I am currently using SHA256 with a salt to hash my passwords. Is it better to continue using SHA256 or should I change to SHA512? 回答1: Switching to SHA512 will hardly make your website more secure. You should not write your own password hashing function. Instead, use an existing implementation. SHA256 and SHA512 are message digests , they were never meant to be password-hashing (or key-derivation) functions. (Although a message digest could be used a building block for a KDF, such as in

JAVA SHA256加密

喜欢而已 提交于 2019-11-27 00:23:03
/** * 利用java原生的类实现SHA256加密 * * @param str * @return */ private String getSHA256(String str) { MessageDigest messageDigest; String encodestr = ""; try { messageDigest = MessageDigest.getInstance("SHA-256"); messageDigest.update(str.getBytes("UTF-8")); encodestr = byte2Hex(messageDigest.digest()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return encodestr; } //15 转16进制 /** * 将byte转为16进制 * * @param bytes * @return */ private static String byte2Hex(byte[] bytes) { StringBuffer stringBuffer = new StringBuffer();

Generating a sha256 from the Linux command line [closed]

徘徊边缘 提交于 2019-11-26 23:47:10
问题 I know the string "foobar" generates the SHA 256 hash c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2 using http://hash.online-convert.com/sha256-generator However the command line shell: hendry@x201 ~$ echo foobar | sha256sum aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f - Generates a different hash. What am I missing? 回答1: echo will normally output a newline, which is suppressed with -n . Try this: echo -n foobar | sha256sum 回答2: If you have installed