Ethereum: Test sum against hash – differences and similarities
When it comes to digital signatures and data check in the Ethereum blockchain, two basic concepts come into play: test sums and hashes. While both algorithms offer a way to ensure data integrity and authenticity, they differ in their approach, functionality and use.
Test sum algorithm (SHA-1)
A test sum algorithm is a one-way having function that creates a string with a fixed size, which is referred to as hash value or cheek. It was developed to check the authenticity and integrity of data by comparing it with a previously generated hash value.
Example: Checking a digital signature with SHA-1
`Python
Import Hashlib
Create a new SHA 1 Hash object
Hash_object = Hashlib.sha1 ()
The message to be checked (the digital signature)
Message = B "Example signature"
Update the hash object with the message
Hash_object.update (message)
Get the hash value
Test sum = hash_object.hexdigest ()
Print ("Checksumal:", checksum)
edition: "E2B9B6CD7F4A1C4CDA ... (Hashed version)"
hash function
A hash function, on the other hand, is a disposable algorithm that takes input data of all size and creates an output with a fixed size (hash value). It was developed to ensure data integrity by creating a clear identifier for each input.
Example: Checking a digital signature with SHA-256
`Python
Import Hashlib
Create a new SHA-256 Hash object
Hash_object = Hashlib.sha256 ()
The message to be checked (the digital signature)
Message = B "Example signature"
Update the hash object with the message
Hash_object.update (message)
Get the hash value
Test sum = hash_object.hexdigest ()
Print ("Checksumal:", check sum)
edition: "D1E87B4A8C7F0DB6 ... (Hashed version)"
Differences and similarities
| Feature | Test sum algorithm (SHA-1) | Hash function (SHA-256) |
| — | — | — |
|
Purpose | Check the data integrity | Make the data authenticity safely |
|
disposable | Disposable having | Disposable encryption |
|
Output size | Characteristics of characters | Output of the variable size (hash value) |
|
Safety | Less secure due to the susceptibility to collisions and preparatory attacks | Safer due to cryptographic properties
|
Use | Check digital signatures, data integrity tests | Authentication, data check |
|
advantages | Fast calculation times for small entrances | Fast calculations for large inputs
Can they be used instead of each other?
No, test sums and hashes are not interchangeable. Checks are mainly used for quick review checks, while Hashes are designed for authentication and cryptographic purposes.
The following example shows how a hash function (SHA-256) is used to check a digital signature:
`Python
Import Hashlib
Create a new SHA-256 Hash object
Hash_object = Hashlib.sha256 ()
The message to be checked (the digital signature)
Message = B "Example signature"
Update the hash object with the message
Hash_object.update (message)
Get the hash value
Test sum = hash_object.hexdigest ()
Print ("Checksumal:", check sum)
edition: "D1E87B4A8C7F0DB6 ... (Hashed version)"
Check the digital signature with SHA-256
attempt:
expected_checksum = Hashlib.sha256 (B "Example signature"). Hexdigest ()
print ("reviews successful:", testum == expected_checksum)
Except Valueeror:
Print ("Verification failed: Hash values that do not match")
Finally, test sums and Hashes in the Ethereum blockchain serve different purposes. Checks are used for quick review checks, while Hashes are designed for authentication and cryptographic purposes. While they can be used in certain scenarios, their use should be used with caution due to the differences in their functions and safety properties.