public void Encode() { Base64Encoding e = new Base64Encoding(); i = "test"; o = e.Encode(i); Assert.Equal(o, "dGVzdA=="); i = "test0"; o = e.Encode(i); Assert.Equal(o, "dGVzdDA="); i = "test00"; o = e.Encode(i); Assert.Equal(o, "dGVzdDAw"); i = "test01"; o = e.Encode(i); Assert.Equal(o, "dGVzdDAx"); i = "test000"; o = e.Encode(i); Assert.Equal(o, "dGVzdDAwMA=="); o = e.Encode(new byte[] { 0, }); Assert.Equal(o, "AA=="); o = e.Encode(new byte[] { 0, 0, }); Assert.Equal(o, "AAA="); o = e.Encode(new byte[] { 0, 0, 0, }); Assert.Equal(o, "AAAA"); i = "Man is distinguished, not only by his reason, but by this singular passion from " + "other animals, which is a lust of the mind, that by a perseverance of delight " + "in the continued and indefatigable generation of knowledge, exceeds the short" + "vehemence of any carnal pleasure." ; string o_encoded = "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz" + "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg" + "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu" + "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo" + "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" ; o = e.Encode(i); //Assert.Equal(o, o_encoded); return; }
[Test] public void Base64() { // All bytes from 0 to ff byte[] sbuf = new byte[256]; for (int i = 0; i != 256; ++i) { sbuf[i] = (byte)i; } byte[] dbuf = Encoding.ASCII.GetBytes("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIj" + "JCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZH" + "SElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWpr" + "bG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6P" + "kJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKz" + "tLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX" + "2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7" + "/P3+/w=="); int len = Base64Encoding.EncodeSize(sbuf.Length); Assert.Equal(dbuf.Length, len); int dst_length; byte[] dst = new byte[len]; Base64Encoding.Encode(sbuf, dst, out dst_length); Assert.Equal(dbuf.Length, dst_length); for (int i = 0; i != dbuf.Length; ++i) { Assert.Equal(dbuf[i], dst[i]); } len = Base64Encoding.DecodeSize(dbuf.Length); Assert.True(len >= sbuf.Length); int src_length; byte[] src = new byte[len]; Base64Encoding.Decode(dst, src, out src_length); Assert.Equal(sbuf.Length, src_length); for (int i = 0; i != sbuf.Length; ++i) { Assert.Equal(sbuf[i], src[i]); } // Random binary data Random r = new Random(); for (int i = 0; i != sbuf.Length; ++i) { sbuf[i] = (byte)(r.Next(0xFF)); } Base64Encoding.Encode(sbuf, dst, out dst_length); Base64Encoding.Decode(dst, src, out src_length); Assert.Equal(sbuf.Length, src_length); for (int i = 0; i != sbuf.Length; ++i) { Assert.Equal(sbuf[i], src[i]); } }
private async Task AddObjectsToNode(string id) { IObjectsApi objectsApi = GeneralTokenConfigurationSettings <IObjectsApi> .SetToken(new ObjectsApi(), await _authServiceAdapter.GetSecondaryTokenTask()); var objectList = objectsApi.GetObjects(id); foreach (KeyValuePair <string, dynamic> objInfo in new DynamicDictionaryItems(objectList.items)) { nodes.Add(new TreeNode(Base64Encoding.Encode((string)objInfo.Value.objectId), objInfo.Value.objectKey, "object", false)); } }