Decrypt text, which was encrypted by CommunityCommons.EncryptString

0
I have a C# application, which communicates via webservices with my Mendix application. One communication item is some really sensitive information, which is stored as encrypted information in the database. It is encrypted using CommunityCommons.EncryptString. Does anyone know which specific algorithms are used to encrypt using this function, or, how can I decrypt these encrypted strings using C#?
asked
1 answers
2

I originally wrote this encrypt/decrypt method before it was moved to the community commons module (from my Exchange module), it's an AES encryption with a 128 bit key, cipher-block chaining with PKCS #5 padding . You can have a look at the implementation of encrypt and decrypt in the community commons module. Also note the base64 encoding/decoding. I couldn't tell you exactly how to implement this in C# but I'm sure there are many examples to be found.

Encryption:

    Cipher c = Cipher.getInstance("AES/CBC/PKCS5PADDING");
    SecretKeySpec k = new SecretKeySpec(key.getBytes(), "AES");
    c.init(Cipher.ENCRYPT_MODE, k);
    byte[] encryptedData = c.doFinal(valueToEncrypt.getBytes());
    byte[] iv = c.getIV();
    return new StringBuilder(Base64.encode(iv)).append(";").append(Base64.encode(encryptedData)).toString();

Decryption:

    Cipher c = Cipher.getInstance("AES/CBC/PKCS5PADDING");
    SecretKeySpec k = new SecretKeySpec(key.getBytes(), "AES");
    String[] s = encryptedPassword.split(";");
    byte[] iv = Base64.decode(s[0]);
    byte[] encryptedData = Base64.decode(s[1]);
    c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
    return new String(c.doFinal(encryptedData));
answered