public static byte[] FromBase64(this string str) { if (string.IsNullOrWhiteSpace(str)) { return(new byte[0]); } return(BASE64.Decode(Encoding.UTF8.GetBytes(str))); }
public void DecodeTest() { var actual = Base64Encoder.Decode("QUJDREVGRw=="); var expected = Encoding.ASCII.GetBytes("ABCDEFG"); Assert.Equal(expected, actual); }
public void Decode_Bytes_Bytes() { byte[] expectedResult = new byte[] { 0x00, 0x01, 0x03, 0x03, 0x07, 0x00 }; byte[] data = new byte[] { 65, 65, 69, 68, 65, 119, 99, 65 }; byte[] result = Base64Encoder.Decode(data); Assert.AreEqual(expectedResult, result); }
private bool AuthenticateCramMd5(NetworkCredential credentials) { var command = new ImapCommand("AUTHENTICATE CRAM-MD5"); var response = _client.SendAndReceive(command); // don't trim the last plus !! var base64 = response.CurrentLine.TrimStart(Characters.Plus).Trim(); var challenge = Base64Encoder.Decode(base64, Encoding.UTF8); var username = credentials.UserName; var password = credentials.Password; var hash = CramMd5Hasher.ComputeHash(password, challenge); var authentication = username + " " + hash; var authCommand = new BlankImapCommand(Base64Encoder.Encode(authentication)); var reader = _client.SendAndReceive(authCommand); while (!reader.IsCompleted) { reader = _client.Receive(false); } return(reader.IsOk); }
public void Data_of_various_length___roundtrips_correclty_as_string() { var sut = new Base64Encoder(); var bytes = new byte[byte.MaxValue + 1]; for (int i = 0; i < bytes.Length; ++i) { bytes[i] = (byte)(255 - i); } for (int i = 0; i < 256; ++i) { Span <byte> source = bytes.AsSpan(0, i + 1); string encoded = sut.Encode(source); #if NETCOREAPP string encodedExpected = Convert.ToBase64String(source); #else string encodedExpected = Convert.ToBase64String(source.ToArray()); #endif Assert.AreEqual(encodedExpected, encoded); Span <byte> decoded = sut.Decode(encoded.AsSpan()); CollectionAssert.AreEqual(source.ToArray(), decoded.ToArray()); } }
public void Decode_ReturnsCorrectText(string source, string expected) { var encoder = new Base64Encoder(); var actual = encoder.Decode(source); Assert.AreEqual(expected, actual); }
public void Decode_String_Bytes() { byte[] expectedResult = new byte[] { 0x00, 0x01, 0x03, 0x03, 0x07, 0x00 }; string data = Encoding.ASCII.GetString(new byte[] { 65, 65, 69, 68, 65, 119, 99, 65 }); byte[] result = Base64Encoder.Decode(data); Assert.AreEqual(expectedResult, result); }
public void Decode_String_ASCII() { const string expectedResult = "Hello world"; string data = Encoding.ASCII.GetString(new byte[] { 83, 71, 86, 115, 98, 71, 56, 103, 100, 50, 57, 121, 98, 71, 81, 61 }); string result = Encoding.ASCII.GetString(Base64Encoder.Decode(data)); Assert.AreEqual(expectedResult, result); }
public void Decode_String_UTF8() { const string expectedResult = "檔案"; string data = Encoding.ASCII.GetString(new byte[] { 53, 113, 113, 85, 53, 113, 71, 73 }); string result = Encoding.UTF8.GetString(Base64Encoder.Decode(data)); Assert.AreEqual(expectedResult, result); }
public void Empty_input_decode_from_string___empty_array() { var sut = new Base64Encoder(); string encoded = string.Empty; byte[] actual = sut.Decode(encoded.AsSpan()); Assert.AreEqual(Array.Empty <byte>(), actual); }
public IActionResult Index() { string test = "{cmd:'tick'},{"; test = Base64Encoder.Encode(test); string tmp = Base64Encoder.Decode(test); return(View()); }
public void Decode_Test() { var base64Encoder = new Base64Encoder(); const string input = "Um9nZXIgRmVkZXJlcg=="; var output = base64Encoder.Decode(input); Assert.AreEqual("Roger Federer", output); }
public void Core_Text_Encoding_Base64Encoder() { var rawValue = "Raw data value"; var encodedValue = string.Empty; var encoder = new Base64Encoder(rawValue); encodedValue = encoder.Encode(); encoder = new Base64Encoder(encodedValue); Assert.IsTrue(encoder.Decode() == rawValue, "Did not work."); }
public void Text_Encoding_Base64Encoder() { var rawValue = "Raw data value"; var encodedValue = TypeExtension.DefaultString; var encoder = new Base64Encoder(rawValue); encodedValue = encoder.Encode(); encoder = new Base64Encoder(encodedValue); Assert.IsTrue(encoder.Decode() == rawValue, "Did not work."); }
public string Post(Guid id, [FromBody] string cmd) { try { cmd = Base64Encoder.Decode(cmd); string result = _service.Update(id, JObject.Parse(cmd)).ToString(); return(Base64Encoder.Encode(result)); } catch { return(Base64Encoder.Encode(IotResultHelper.Error.ToString())); } }
public void Empty_input_decode_from_string___empty_array() { var sut = new Base64Encoder(); string encoded = string.Empty; byte[] actual = sut.Decode(encoded.AsSpan()); // AsSpan() for net48 #if NETCOREAPP Assert.AreEqual(Array.Empty <byte>(), actual); #else Assert.AreEqual(0, actual.Length); #endif }
public string Get(Guid id, string cmd) { try { cmd = Base64Encoder.Decode(cmd); string result = _service.Sync(id, JObject.Parse(cmd)).ToString(); return(Base64Encoder.Encode(result)); } catch { return(Base64Encoder.Encode(IotResultHelper.Error.ToString())); } }
public void Decode() { extent.LoadConfig(AppDomain.CurrentDomain.BaseDirectory + "../../extent-config.xml"); test = extent .StartTest("Decode", "A Decoding Test"); try { Assert.True(Base64Encoder.Decode("U3RyaW5nIHRvIGVuY29kZQ==").Equals("String to encode")); test.Log(LogStatus.Pass, "String was decoded"); } catch (Exception ex) { test.Log(LogStatus.Fail, "<pre>" + ex.StackTrace + "</pre"); } }
public void Decode(string data, byte[] expected) { // Arrange var context = new TestCaseContext(); var sut = new Base64Encoder( context.Options, context.Logger, context.StringEncoder); // Act var result = sut.Decode(data); // Assert Assert.Equal(expected, result); }
public static async Task <MemoryStream> GetDecryptionStreamAsync(Stream input, IMS2SizeHeader size, IMultiArray key, IMultiArray iv, bool zlibCompressed) { using var ms = new MemoryStream(); byte[] encodedBytes = new byte[size.EncodedSize]; await input.ReadAsync(encodedBytes, 0, encodedBytes.Length).ConfigureAwait(false); var encoder = new Base64Encoder(); encoder.Decode(encodedBytes, 0, encodedBytes.Length, ms); if (ms.Length != size.CompressedSize) { throw new ArgumentException("Compressed bytes from input do not match with header size.", nameof(input)); } ms.Position = 0; return(await InternalGetDecryptionStreamAsync(ms, size, key, iv, zlibCompressed).ConfigureAwait(false)); }
/// <summary> /// Cram-MD5 authorization. /// http://tools.ietf.org/html/rfc2195 /// </summary> private bool AuthenticateCramMd5(NetworkCredential credentials) { var command = new SmtpCommand("AUTH CRAM-MD5"); var response = _client.SendAndReceive(command); var base64 = response.CurrentLine.Substring(4).TrimEnd(); var challenge = Base64Encoder.Decode(base64, Encoding.UTF8); var username = credentials.UserName; var password = credentials.Password; var hash = CramMd5Hasher.ComputeHash(password, challenge); var authentication = username + " " + hash; var reader = _client.SendAndReceive(new SmtpCommand(Base64Encoder.Encode(authentication))); return(reader.IsOk); }
private bool AuthenticateCramMd5(NetworkCredential credentials) { var command = new Pop3Command("AUTH CRAM-MD5"); var response = _client.SendAndReceive(command); // don't trim the last plus !! var base64 = response.CurrentLine.TrimStart(Characters.Plus).Trim(); var challenge = Base64Encoder.Decode(base64, Encoding.UTF8); var username = credentials.UserName; var password = credentials.Password; var hash = CramMd5Hasher.ComputeHash(password, challenge); var authentication = username + " " + hash; var authCommand = new Pop3Command(Base64Encoder.Encode(authentication)); _client.Send(authCommand); return(_client.Receive().IsPositive); }
public void DecodeStringTest() { var actual = Base64Encoder.Decode("QUJDREVGRw==", Encoding.ASCII); Assert.Equal("ABCDEFG", actual); }
public void Decode_String_Argument0Length() { Assert.Throws <IndexOutOfRangeException>(() => Base64Encoder.Decode(string.Empty)); }
public void Load() { if (!File.Exists(dataPath)) { FirstSave(); } try { string asJSON = File.ReadAllText(dataPath); PlayerData playerData = JsonUtility.FromJson <PlayerData>(JSON_ONLY ? asJSON : Base64Encoder.Decode(asJSON)); } // In case of messed up file catch (Exception) { FirstSave(); } finally { string asJSON = File.ReadAllText(dataPath); PlayerData playerData = JsonUtility.FromJson <PlayerData>(JSON_ONLY ? asJSON : Base64Encoder.Decode(asJSON)); foreach (IPlayerData playerDataController in playerDataVariables) { playerDataController.Load(playerData); } // Adds back the eventual missing fields Save(); onLoad.Invoke(); } }
public void Decode_Bytes_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => Base64Encoder.Decode((byte[])null)); }
public void Decode_String_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => Base64Encoder.Decode((string)null)); }
public void Decode_Bytes_Argument0Length() { Assert.Throws <IndexOutOfRangeException>(() => Base64Encoder.Decode(new byte[0])); }
public static string Decrypt(string encodedPassword) { string result = Base64Encoder.Decode(encodedPassword); return(result); }
public void Malformed_input_to_byte_array___throws_FormatException(string input) { var sut = new Base64Encoder(); Assert.Throws <FormatException>(() => sut.Decode(input.AsSpan())); }