Esempio n. 1
0
        public static (string encryptedPassword, string key) Encrypt(string password)
        {
            byte[] keyBytes      = SimpleFernet.GenerateKey().UrlSafe64Decode();
            var    passwordBytes = System.Text.Encoding.Unicode.GetBytes(password);
            string encrypted     = SimpleFernet.Encrypt(keyBytes, passwordBytes);
            string key           = keyBytes.UrlSafe64Encode();

            return(encrypted, key);
        }
Esempio n. 2
0
        public void CanEncodeDecode()
        {
            // Arrange
            var key   = SimpleFernet.GenerateKey().UrlSafe64Decode();
            var src   = "hello";
            var src64 = src.ToBase64String();

            // Act
            var token     = SimpleFernet.Encrypt(key, src64.UrlSafe64Decode());
            var decoded64 = SimpleFernet.Decrypt(key, token, out var timestamp);
            var decoded   = decoded64.UrlSafe64Encode().FromBase64String();

            // Assert
            Assert.Equal(src, decoded);
        }