0

I am trying to decode the value I find in tags "hash" attribute, like "b4002e70b6cb73b1093d83e2b8e6c734", to a byte array so I can call the noteStore.getResourceByHash method correctly. Right now I am constantly getting EDAMNotFoundException errors, so I am guessing I am not computing the hash correctly.

Did anyone already figure this out?

Here is the code. I tried many different methods. This is the current state of affairs:

System.Security.Cryptography.MD5CryptoServiceProvider test123 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes("b4002e70b6cb73b1093d83e2b8e6c733");
data = test123.ComputeHash(data);
var note = noteStore.getResourceByHash(evernoteToken, noteGuid, data, true, false, false);
cfrick
  • 35,203
  • 6
  • 56
  • 68
Corstiaan
  • 1,114
  • 15
  • 34

2 Answers2

1

It looks like your hexadecimal number is 16 bytes. Is it a GUID? If so, you can just use this:

var id = Guid.Parse("b4002e70b6cb73b1093d83e2b8e6c733").ToByteArray();

Using Encoding.ASCII.GetBytes is definitely not right, because that will get you a byte per char, corresponding to the ASCII value for that character. You want a byte per two char (hexadecimal decoding).

Timothy Shields
  • 75,459
  • 18
  • 120
  • 173
0

Evernote references resources via the resource's GUID or the hash of the binary file stream.

If you are looking to get the hash of a resource, you must take the hash of the file you have uploaded to Evernote. The code might look something like this:

    public string CalculateFileHashTotal(string fileLocation)
            {
                using (var md5 = MD5.Create())
                {
                    using (var stream = File.OpenRead(fileLocation))
                    {
                        byte[] b = md5.ComputeHash(stream);
                        stream.Close();
                        return BitConverter.ToString(B).Replace("-", "").ToLower();
                    }
                }
            }

If you are looking to get a resource that has already been uploaded or you don't have access to the file, referencing the resource via the GUID would likely be your best option.

You can call the getNote method to get the note object which will have the attribute resources which contains a list of Resources each of has the attribute GUID. This GUID can be used to call any of the following methods (each is linked to Evernote API reference):

mattcarrollcode
  • 3,429
  • 16
  • 16