コード例 #1
0
ファイル: EncodeExtensions.cs プロジェクト: weikety/ECode
        public static byte[] FromBase64(this string str)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                return(new byte[0]);
            }

            return(BASE64.Decode(Encoding.UTF8.GetBytes(str)));
        }
コード例 #2
0
        public void DecodeTest()
        {
            var actual   = Base64Encoder.Decode("QUJDREVGRw==");
            var expected = Encoding.ASCII.GetBytes("ABCDEFG");

            Assert.Equal(expected, actual);
        }
コード例 #3
0
 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);
 }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: Roundtrips.cs プロジェクト: gfoidl/Base64
        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());
            }
        }
コード例 #6
0
        public void Decode_ReturnsCorrectText(string source, string expected)
        {
            var encoder = new Base64Encoder();

            var actual = encoder.Decode(source);

            Assert.AreEqual(expected, actual);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: Decode.cs プロジェクト: jinqi166/Base64
        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);
        }
コード例 #11
0
ファイル: HomeController.cs プロジェクト: deeyi2000/LanhNet
        public IActionResult Index()
        {
            string test = "{cmd:'tick'},{";

            test = Base64Encoder.Encode(test);
            string tmp = Base64Encoder.Decode(test);

            return(View());
        }
コード例 #12
0
        public void Decode_Test()
        {
            var base64Encoder = new Base64Encoder();

            const string input  = "Um9nZXIgRmVkZXJlcg==";
            var          output = base64Encoder.Decode(input);

            Assert.AreEqual("Roger Federer", output);
        }
コード例 #13
0
        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.");
        }
コード例 #14
0
        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.");
        }
コード例 #15
0
 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()));
     }
 }
コード例 #16
0
ファイル: EmptyInput.cs プロジェクト: gfoidl/Base64
        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
        }
コード例 #17
0
 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()));
     }
 }
コード例 #18
0
 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");
     }
 }
コード例 #19
0
        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);
        }
コード例 #20
0
        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));
        }
コード例 #21
0
        /// <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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        public void DecodeStringTest()
        {
            var actual = Base64Encoder.Decode("QUJDREVGRw==", Encoding.ASCII);

            Assert.Equal("ABCDEFG", actual);
        }
コード例 #24
0
 public void Decode_String_Argument0Length()
 {
     Assert.Throws <IndexOutOfRangeException>(() => Base64Encoder.Decode(string.Empty));
 }
コード例 #25
0
    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();
        }
    }
コード例 #26
0
 public void Decode_Bytes_ArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => Base64Encoder.Decode((byte[])null));
 }
コード例 #27
0
 public void Decode_String_ArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => Base64Encoder.Decode((string)null));
 }
コード例 #28
0
 public void Decode_Bytes_Argument0Length()
 {
     Assert.Throws <IndexOutOfRangeException>(() => Base64Encoder.Decode(new byte[0]));
 }
コード例 #29
0
ファイル: PasswordEncrypter.cs プロジェクト: ppm2k2/IDA
        public static string Decrypt(string encodedPassword)
        {
            string result = Base64Encoder.Decode(encodedPassword);

            return(result);
        }
コード例 #30
0
ファイル: InvalidInput.cs プロジェクト: AigioL/Base64
        public void Malformed_input_to_byte_array___throws_FormatException(string input)
        {
            var sut = new Base64Encoder();

            Assert.Throws <FormatException>(() => sut.Decode(input.AsSpan()));
        }