Would like to know how to encrypt a file (lets say a .txt o开发者_如何学运维r .xml) with SHA512 hash ? How to proceed ?
What i would want to do is.. check if the file exist.. open it and then read it while unencrypting it.
Thanks!
That is not possible. SHA512 is a hashing algorithm, not an encryption algorithm.
If you want to get the hash for a file, you can use the SHA512 class.
Example:
Dim data As Byte() = File.ReadAllBytes("file.txt")
Dim result As Byte()
Dim sha As New SHA512Managed()
result = sha.ComputeHash(data)
A hash tells you the integrity of a series of bytes.
Encryption obscures or hides information.
To encrypt of file you could follow the MSDN tutorial:
http://msdn.microsoft.com/en-us/library/system.io.file.encrypt.aspx
Since you mention you want to do this 'on the fly', you could also select one of the .NET encryption algorithms and implement your own using the FileStream object:
http://support.microsoft.com/kb/307010
A google search reveals a wealth of information on the subject.
精彩评论