#1 2022-12-08 14:19:05

Greg0r
Member
Registered: 2019-01-28
Posts: 48

Decrypt using mORMot

Hello,

Can anyone help me with mORMot(v1 or V2 whatever ) decrypt  string encrypted which such C# code?

public string Encrypt(string data, string key)
        {
            if (string.IsNullOrWhiteSpace(data))
            {
                return string.Empty;
            }

            using var aes = Aes.Create();
            aes.Key = Encoding.UTF8.GetBytes(key);
            var iv = Convert.ToBase64String(aes.IV);
            var transform = aes.CreateEncryptor(aes.Key, aes.IV);
            using var memoryStream = new MemoryStream();
            using var cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Write);
            using (var streamWriter = new StreamWriter(cryptoStream))
            {
                streamWriter.Write(data);
            }

            return iv + Convert.ToBase64String(memoryStream.ToArray());
        }

Last edited by Greg0r (2022-12-08 16:37:49)

Offline

#2 2022-12-08 16:38:40

Greg0r
Member
Registered: 2019-01-28
Posts: 48

Re: Decrypt using mORMot

ps. I know it's perhapns not the safest AES implmentation but it's more than enough for my purposes.

Offline

#3 2022-12-09 22:59:24

flydev
Member
From: France
Registered: 2020-11-27
Posts: 42
Website

Re: Decrypt using mORMot

Hi, you can take a look there for example (v1, it's easy to port on v2), and in the source of `mormot.crypt.core` for more details (read the comments).

You can also find more recents details on a good blog post .

Offline

Board footer

Powered by FluxBB