Decrypt with clarion

Is it possible to decrypt a value with Clarion, perhaps with Cryptonite, from an Encrypt in C#? I have a source code in C# with a password. I have tried it with Cryptonite but without result.

i know the value of one field that is omar11 and the ecriptation is 2boh1Rk2ze3J8grK7pAiQQ==

the source decrypt correctly the value, but i need decrypt with clarion. Everythig is in the code

this is the source code that can run in this site https://www.jdoodle.com/

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.IO;

using System;

class Program
{
    static void Main() {
        string result;
        // Create an instance of the Cryptography class using the constructor that takes a SymmetricAlgorithm parameter
        Cryptography cryptography = new Cryptography(new RijndaelManaged());
        result = cryptography.Decrypt("2boh1Rk2ze3J8grK7pAiQQ==");
        Console.Write("La Contraseña desencriptada es: " + result);
    }
}

public class Cryptography
{
    //================================================
    // Fields
    //================================================
    private string Key;
    private SymmetricAlgorithm mobjCryptoService;

    //================================================
    // Methods
    //================================================
    public Cryptography(SymmetricAlgorithm ServiceProvider)
    {
        this.Key = "[email protected]";
        this.mobjCryptoService = ServiceProvider;
    }

    public string Decrypt(string Source)
    {
        byte[] buffer = Convert.FromBase64String(Source);
        MemoryStream stream = new MemoryStream();
        byte[] legalKey = this.GetLegalKey(this.Key);
        this.mobjCryptoService.Key = legalKey;
        this.mobjCryptoService.IV = legalKey;
        ICryptoTransform transform = this.mobjCryptoService.CreateDecryptor();
        CryptoStream stream2 = new CryptoStream(stream,  transform,  CryptoStreamMode.Write);
        stream2.Write(buffer,  0,  buffer.Length);
        stream2.FlushFinalBlock();
        byte[] bytes = stream.ToArray();
        stream.Close();
        stream = null;
        stream2.Close();
        stream2 = null;
        return Encoding.UTF8.GetString(bytes);
    }

    public string Encrypt(string Source)
    {
        byte[] bytes = Encoding.ASCII.GetBytes(Source);
        MemoryStream stream = new MemoryStream();
        byte[] legalKey = this.GetLegalKey(this.Key);
        this.mobjCryptoService.Key = legalKey;
        this.mobjCryptoService.IV = legalKey;
        ICryptoTransform transform = this.mobjCryptoService.CreateEncryptor();
        CryptoStream stream2 = new CryptoStream(stream,  transform,  CryptoStreamMode.Write);
        stream2.Write(bytes,  0,  bytes.Length);
        stream2.FlushFinalBlock();
        byte[] inArray = stream.ToArray();
        stream.Close();
        stream = null;
        stream2.Close();
        stream2 = null;
        return Convert.ToBase64String(inArray);
    }

    private byte[] GetLegalKey(string Key)
    {
        string s = "";
        char paddingChar = char.Parse(" ");
        if (this.mobjCryptoService.LegalKeySizes.Length > 0)
        {
            int minSize = this.mobjCryptoService.LegalKeySizes[0].MinSize;
            while ((Key.Length * 8) > minSize)
            {
                minSize += this.mobjCryptoService.LegalKeySizes[0].SkipSize;
            }
            s = Key.PadRight(minSize / 8,  paddingChar);
        }
        else
        {
            s = Key;
        }
        return Encoding.ASCII.GetBytes(s);
    }

    //================================================
    // Properties
    //================================================
    public string SetKey
    {
        get
        {
            return this.Key;
        }
        set
        {
            this.Key = value;
        }
    }

    //================================================
    // Nested Types
    //================================================
    public enum SymmProvEnum
    {
        DES, 
        RC2, 
        Rijndael
    }
}
1 Like

Looks like standard symmetric Base64 encryption.

See:

https://www.capesoft.com/docs/CryptoNite/CryptoNite.htm#SymmetricallyEncryptingAString

I tried that option and it didn’t work or I did something wrong.

Base64 is an encoding not an encryption. I agree that the binary value appsars to be base64 encoded; and thus meeds yo be base64 decoded before decrypting.

I have tried several ways with cryptonite but I think the problem is this c# routine and I don’t know how to convert it to clarion

private byte GetLegalKey(string Key)
{
string s = “”;
char paddingChar = char.Parse(" ");
if (this.mobjCryptoService.LegalKeySizes.Length > 0)
{
int minSize = this.mobjCryptoService.LegalKeySizes[0].MinSize;
while ((Key.Length * 8) > minSize)
{
minSize += this.mobjCryptoService.LegalKeySizes[0].SkipSize;
}
s = Key.PadRight(minSize / 8, paddingChar);
}
else
{
s = Key;
}
return Encoding.ASCII.GetBytes(s);
}

can you please show your code - otherwise we are just guessing.

I am guessing you are using AES - maybe 256 bit but perhaps 128?

It might be worth reading of the “Differences Between Rijndael and AES”

i use a cryptonite demo and tested all options

the provider of c# code is RijndaelManaged, so cryptonite support this provider? i search in documentation and not found this provider

I don’t know but that is why I provided the earlier link regarding differences to AES. My reading is that it would be compatible providing you used a block size of 128.

Essentially, if you want to use RijndaelManaged as AES you need to make sure that:

1. The block size is set to 128 bits
2. You are not using CFB mode, or if you are the feedback size is also 128 bits