cryptographic-hash-function

MD5 Hash and Base64 encoding

梦想的初衷 提交于 2019-11-28 21:26:46
If I have a 32 character string (an MD5 hash) and I encode it using Base64, what's the maximun length of the encoded string? An MD5 value is always 22 (useful) characters long in Base64 notation. Many Base64 algorithms will also append 2 characters of padding when encoding an MD5 hash, bringing the total to 24 characters. The padding adds no useful information and can be discarded. Only the first 22 characters matter. Here's why: An MD5 hash is a 128-bit value. Every character in a Base64 string contains 6 bits of information, because there are 64 possible values for the character, and it

MD5 is 128 bits but why is it 32 characters?

浪子不回头ぞ 提交于 2019-11-28 15:02:33
问题 I read some docs about md5, it said that its 128 bits, but why is it 32 characters? I can't compute the characters. 1 byte is 8 bits if 1 character is 1 byte then 128 bits is 128/8 = 16 bytes right? EDIT: SHA-1 produces 160 bits, so how many characters are there? 回答1: 32 chars as hexdecimal representation, thats 2 chars per byte. 回答2: I wanted summerize some of the answers into one post. First, don't think of the MD5 hash as a character string but as a hex number. Therefore, each digit is a

MD5 Hash and Base64 encoding

谁说胖子不能爱 提交于 2019-11-27 13:50:10
问题 If I have a 32 character string (an MD5 hash) and I encode it using Base64, what's the maximun length of the encoded string? 回答1: An MD5 value is always 22 (useful) characters long in Base64 notation. Many Base64 algorithms will also append 2 characters of padding when encoding an MD5 hash, bringing the total to 24 characters. The padding adds no useful information and can be discarded. Only the first 22 characters matter. Here's why: An MD5 hash is a 128-bit value. Every character in a

How do one-way hash functions work? (Edited)

Deadly 提交于 2019-11-27 10:57:12
I read the Wikipedia article about md5 hashes but I still can't understand how a hash can't be "reconstituted" back to the original text. Could someone explain to someone who knows very little about cryptography how this works? What part of the function makes it one-way? Since everyone until now has simply defined what a hash function was, I will bite. A one-way function is not just a hash function -- a function that loses information -- but a function f for which, given an image y ("SE" or 294 in existing answers), it is difficult to find a pre-image x such that f(x)=y . This is why they are

C# SHA-1 vs. PHP SHA-1…Different Results?

邮差的信 提交于 2019-11-27 03:56:23
I am trying to calculate a SHA-1 Hash from a string, but when I calculate the string using php's sha1 function I get something different than when I try it in C#. I need C# to calculate the same string as PHP (since the string from php is calculated by a 3rd party that I cannot modify). How can I get C# to generate the same hash as PHP? Thanks!!! String = s934kladfklada@a.com C# Code (Generates d32954053ee93985f5c3ca2583145668bb7ade86) string encode = secretkey + email; UnicodeEncoding UE = new UnicodeEncoding(); byte[] HashValue, MessageBytes = UE.GetBytes(encode); SHA1Managed SHhash = new

How come MD5 hash values are not reversible?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 15:53:22
One concept I've always wondered about is the use of cryptographic hash functions and values. I understand that these functions can generate a hash value that is unique and virtually impossible to reverse, but here's what I've always wondered: If on my server, in PHP I produce: md5("stackoverflow.com") = "d0cc85b26f2ceb8714b978e07def4f6e" When you run that same string through an MD5 function, you get the same result on your PHP installation. A process is being used to produce some value, from some starting value. Doesn't this mean that there is some way to deconstruct what is happening and

MD5 algorithm in Objective-C

邮差的信 提交于 2019-11-26 13:56:37
How to calculate the MD5 in Objective-C? epatel md5 is available on the iPhone and can be added as an addition for ie NSString and NSData like below. MyAdditions.h @interface NSString (MyAdditions) - (NSString *)md5; @end @interface NSData (MyAdditions) - (NSString*)md5; @end MyAdditions.m #import "MyAdditions.h" #import <CommonCrypto/CommonDigest.h> // Need to import for CC_MD5 access @implementation NSString (MyAdditions) - (NSString *)md5 { const char *cStr = [self UTF8String]; unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5( cStr, (int)strlen(cStr), result ); // This is the md5 call

C# SHA-1 vs. PHP SHA-1…Different Results?

烈酒焚心 提交于 2019-11-26 12:42:15
问题 I am trying to calculate a SHA-1 Hash from a string, but when I calculate the string using php\'s sha1 function I get something different than when I try it in C#. I need C# to calculate the same string as PHP (since the string from php is calculated by a 3rd party that I cannot modify). How can I get C# to generate the same hash as PHP? Thanks!!! String = s934kladfklada@a.com C# Code (Generates d32954053ee93985f5c3ca2583145668bb7ade86) string encode = secretkey + email; UnicodeEncoding UE =

How do one-way hash functions work? (Edited)

百般思念 提交于 2019-11-26 10:23:33
问题 I read the Wikipedia article about md5 hashes but I still can\'t understand how a hash can\'t be \"reconstituted\" back to the original text. Could someone explain to someone who knows very little about cryptography how this works? What part of the function makes it one-way? 回答1: Since everyone until now has simply defined what a hash function was, I will bite. A one-way function is not just a hash function -- a function that loses information -- but a function f for which, given an image y (

How to hash some string with sha256 in Java?

断了今生、忘了曾经 提交于 2019-11-26 10:05:13
How to hash some string with sha256 in Java ? Does anybody know any free library for this ? Jon Skeet SHA-256 isn't an "encoding" - it's a one-way hash. You'd basically convert the string into bytes (e.g. using text.getBytes(StandardCharsets.UTF_8) ) and then hash the bytes. Note that the result of the hash would also be arbitrary binary data, and if you want to represent that in a string, you should use base64 or hex... don't try to use the String(byte[], String) constructor. e.g. MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(text.getBytes