Skip to content

Instantly share code, notes, and snippets.

@evernotegists
Created December 9, 2014 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evernotegists/793b9c5cf61276e21b68 to your computer and use it in GitHub Desktop.
Save evernotegists/793b9c5cf61276e21b68 to your computer and use it in GitHub Desktop.
Convert a resource hash to a byte array for noteStore.getResourceByHash
/// To be used alongside our Cloud SDK: https://github.com/evernote/evernote-cloud-sdk-ios
/// "hashCode" below is the "hash=" value extracted from the en-media tag
byte[] bytes = ConvertStringToByteArray(hashCode);
Resource resrc = enNoteStore.getResourceByHash(authToken, noteGuid, bytes, true, false, false);
string resourceContent = Convert.ToBase64String(resrc.Data.Body);
/// The function convertStringToByteArray is:
private byte[] ConvertStringToByteArray(string stringToConvert)
{
int length = stringToConvert.Length;
int upperBound = length / 2;
if (length % 2 == 0) {
upperBound -= 1;
} else {
stringToConvert = "0" + stringToConvert;
}
byte[] bytes = new byte[upperBound];
for (int i = 0; i <= upperBound; i++) {
bytes(i) = Convert.ToByte(stringToConvert.Substring(i * 2, 2), 16);
}
return bytes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment