SHA1Managed from System.Security.Cryptography

An example of using the SHA1Managed class from System.Security.Cryptography. (From this blog entry.)

This generates an SHA1 hash from a file called "C:/report.txt", as a base64 string.

>>> from System import Convert >>> from System.IO import FileStream, FileMode, FileAccess >>> from System.Security.Cryptography import SHA1Managed >>> >>> stream = FileStream("C:/report.txt", FileMode.Open, FileAccess.Read) >>> sha1 = SHA1Managed >>> Convert.ToBase64String(sha1.ComputeHash(stream)) '2jmj7l5rSw0yVb/vlWAYkK/YBwk=' >>>

Back to Contents.