Ejemplo n.º 1
0
    public void NastyHexStr()
    {
        var input  = "FE -FE-fe  _ąćpo";
        var output = HexStr.ToBytes(input);

        Assert.Equal(254, output[0]);
        Assert.Equal(254, output[1]);
        Assert.Equal(254, output[2]);
    }
Ejemplo n.º 2
0
    public void WellFormedHexStr()
    {
        var input = "FF-00-0A";

        var output = HexStr.ToBytes(input);

        Assert.Equal(255, output[0]);
        Assert.Equal(0, output[1]);
        Assert.Equal(10, output[2]);
    }
Ejemplo n.º 3
0
        public IActionResult SetKey([FromBody, Required] string key)
        {
            var keyBytes = HexStr.ToBytes(key);

            try
            {
                symmetricService.SetKey(keyBytes);
            }
            catch (CryptographicException ex)
            {
                var error_desc = new
                {
                    ErrorCode = StatusCodes.Status422UnprocessableEntity,
                    Message   = ex.Message
                };
                var result = new JsonResult(error_desc);
                result.StatusCode = error_desc.ErrorCode;
                return(result);
            }
            return(new NoContentResult());
        }
Ejemplo n.º 4
0
 /// <summary>Set key pair to the given one.</summary>
 /// <param name="pair"><c>KeyPair</c> in hex string format, like that returned by <c>GetKeys()</c></param>
 public void SetKeys(KeyPair pair)
 {
     rsa.ImportRSAPrivateKey(HexStr.ToBytes(pair.PrivateKey), out var dummyPriv);
     rsa.ImportRSAPublicKey(HexStr.ToBytes(pair.PublicKey), out var dummyPub);
 }