When a string is encoded with Base64, the only character that is not allowed in the Azure storage key column is a slash ('/'). To fix this, simply replace the slash character with another character that is (1) valid in the Azure Table storage key column, and (2) is not a Base64 character. The most common example I found (which is given in other answers) is to replace a slash ('/') with an underscore ('_').
private static String EncodeToKey(String originalKey) { var keyBytes = System.Text.Encoding.UTF8.GetBytes(originalKey); var base64 = System.Convert.ToBase64String(keyBytes); return base64.Replace('/','_'); }
When decoding, simply cancel the replaced character (first!), And then Base64 decode the resulting string. That is all that is needed.
private static String DecodeFromKey(String encodedKey) { var base64 = encodedKey.Replace('_', '/'); byte[] bytes = System.Convert.FromBase64String(base64); return System.Text.Encoding.UTF8.GetString(bytes); }
Some people have suggested that other Base64 characters also require encoding. According to the Azure Table Storage docs , this is not the case.
Jason weber
source share