SHA-1: Difference between revisions

From Rosetta Code
Content added Content deleted
(Introduce SHA-1 with 2 lines of Factor code.)
 
(Link to MD5 for Java since it would be a very small change)
Line 16: Line 16:


The implementation is at [https://github.com/slavapestov/factor/blob/master/basis/checksums/sha/sha.factor basis/checksums/sha/sha.factor].
The implementation is at [https://github.com/slavapestov/factor/blob/master/basis/checksums/sha/sha.factor basis/checksums/sha/sha.factor].
=={{header|Java}}==
The solution to this task would be a small modification to [[MD5#Java|MD5]] (replacing "MD5" with "SHA-1" as noted [http://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#MessageDigest here]).

Revision as of 21:08, 18 January 2012

SHA-1 is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

SHA-1 or SHA1 is a message digest algorithm; it transforms a message into a 160-bit hash. SHA-1 often appears in security protocols; for example, many HTTPS websites use RSA with SHA-1 to secure their connections. BitTorrent uses SHA-1 to verify downloads. Git and Mercurial use SHA-1 digests to identify commits.

A US government standard, FIPS 180-1, defines SHA-1.

  • Warning: SHA-1 has known weaknesses. Users may consider a stronger alternative, such as SHA-256 (from the SHA-2 family) or the upcoming SHA-3.

Find the SHA-1 message digest for a string of octets. You may either call a SHA-1 library, or implement SHA-1 in your language. Both approaches interest Rosetta Code.

Factor

Factor provides sha1 in the checksums.sha vocabulary. In Factor, checksum-bytes returns a sequence of bytes; hex-string converts this sequence to a hexadecimal string.

IN: scratchpad USING: checksums checksums.sha ;
IN: scratchpad "Rosetta Code" sha1 checksum-bytes hex-string .
"48c98f7e5a6e736d790ab740dfc3f51a61abe2b5"

The implementation is at basis/checksums/sha/sha.factor.

Java

The solution to this task would be a small modification to MD5 (replacing "MD5" with "SHA-1" as noted here).