View Single Post
Old 01-26-2011, 07:16 AM   #49
Junior Member
petersem began at the beginning.
Posts: 3
Karma: 10
Join Date: Jan 2011
Device: Kindle
Need help to understand collections.Json file

I understand that file references in the kindle's collections.json file are SHA1 hashes of the full filename and path.

I have figured out how to write some .net code to replicate these hashes as a first step to writing my own kindle book collection utility.

here's the code:

Public Shared Function GetHash(ByVal fileName As String) As String
'[TODO] ** Files with an _ in them do not encode the same as on the kindle! WHY??

Dim bytes As Byte() = Encoding.UTF8.GetBytes(fileName)
Using hashAlg As HashAlgorithm = New SHA1Managed
hashAlg.TransformFinalBlock(bytes, 0, bytes.Length)
Return String.Format("*{0}", BitConverter.ToString(hashAlg.Hash).Replace("-", String.Empty).ToLower)
End Using
End Function

What i DO NOT UNDERSTAND is that if one of the books has an underscore '_' in the filename, then i get different hash using the above function than what is generated by the Kindle. For all other files, the hash is the same.

Why are underscores treated differently and are there any other special characters that are similar to underscores? How do adapt my code to manage this?

thanks in advance

petersem is offline   Reply With Quote