How to Decrypt data that uses Chilkat for Encryption without using Chilcat library

Aegir

We have a Windows Phone 8 app that needs to communicate with a web service that uses Chilkat to encrypt some data. As far as I know, Chilkat does not support the Windows Phone platform. I have the key and other info about how the data is encrypted (such as the encryption algorithm name, key-length etc.), but will I be able to encrypt/decrypt on Windows Phone without having this library? (We already have android/ios apps that use the same service and they use the chilkat library to crypt the data)

class Program
{
    static readonly string keyString = "MyKey";
    static readonly string iv = "MyIV";
    static Encoding TheEncoding = Encoding.UTF8;

    static void Main(string[] args)
    {
        //I got Chilkat and BouncyCastle via NuGet
        //https://www.nuget.org/packages/WinRTBouncyCastle/0.1.1.1
        //chilcat-win32

        var original = "clear text";

        var chilkatCrypt = GetChilkat3Des();

        //this is equalent to an encrypted text I get from the service
        var ckEncrypted = chilkatCrypt.EncryptStringENC(original);

        var ckDecrypted = chilkatCrypt.DecryptStringENC(ckEncrypted);

        if (!string.Equals(original, ckDecrypted)) throw new ArgumentException("chilkat encrypt/decrypt failure...");

        //now comes the challenge, to decrypt the Chilkat encryption with BouncyCastle (or what ever crypto lib that runs on WP8) 
        //this is where i need help :)
        byte[] chilkatEncBytes = System.Text.Encoding.UTF8.GetBytes(ckEncrypted);
        var bouncyDecrypted = BouncyCastleDecrypt(chilkatEncBytes);
    }

    public static Chilkat.Crypt2 GetChilkat3Des()
    {
        var crypt = new Chilkat.Crypt2();

        if (!crypt.UnlockComponent("Start my 30-day Trial"))
        {
            throw new Exception("Unlock Chilkat failed");
        }

        crypt.CryptAlgorithm = "3des";
        crypt.CipherMode = "cbc";
        crypt.KeyLength = 192;
        crypt.PaddingScheme = 0;
        //  It may be "hex", "url", "base64", or "quoted-printable".
        crypt.EncodingMode = "hex";
        crypt.SetEncodedIV(iv, crypt.EncodingMode);
        crypt.SetEncodedKey(keyString, crypt.EncodingMode);
        return crypt;
    }

    //this code is more or less copied from here:
    //http://nicksnettravels.builttoroam.com/post/2012/03/27/TripleDes-Encryption-with-Key-and-IV-for-Windows-Phone.aspx
    public static byte[] RunBouncyCastleTripleDes(byte[] input, bool encrypt)
    {
        byte[] byteKey = new byte[24];

        Buffer.BlockCopy(TheEncoding.GetBytes(keyString), 0, byteKey, 0, TheEncoding.GetBytes(keyString).Length);

        var IV = new byte[8];

        Buffer.BlockCopy(TheEncoding.GetBytes(iv), 0, IV, 0, TheEncoding.GetBytes(iv).Length);

        var keyParam = new Org.BouncyCastle.Crypto.Parameters.DesEdeParameters(byteKey);

        var ivParam = new Org.BouncyCastle.Crypto.Parameters.ParametersWithIV(keyParam, IV);
        var engine = Org.BouncyCastle.Security.CipherUtilities.GetCipher("DESede/CBC/PKCS5Padding");

        engine.Init(encrypt, ivParam);
        var output = engine.DoFinal(input);

        return output;
    }

    public static byte[] BouncyCastleEncrypt(byte[] input)
    {
        return RunBouncyCastleTripleDes(input, true);
    }

    public static byte[] BouncyCastleDecrypt(byte[] input)
    {
        return RunBouncyCastleTripleDes(input, false);
    }
}
jww

I have the key and other info about how the data is encrypted (such as the encryption algorithm name, key-length etc.), but will I be able to encrypt/decrypt on Windows Phone without having this library?

It depends, buts the answer is probably yes.

If they have a home-grown implementation of well known algorithms, then they might have a bug and the answer could be NO.

If they are using well-known algorithms form well vetted libraries and have fully specified the algorithms and parameters, the the answer is likely YES.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to decode/decrypt MD5 encryption using Java

From Dev

How to decrypt simple XOR encryption

From Dev

How to decrypt simple XOR encryption

From Dev

How to decrypt data using the BouncyCastle Blowfish implementation?

From Dev

How to decrypt data using the BouncyCastle Blowfish implementation?

From Dev

How to paginate data from server without using library in recyclerview?

From Dev

How to decrypt with WinRT without changing existing encryption code in .NET Desktop App?

From Dev

Encrypt / Decrypt UIImage in Swift using AES Encryption

From Dev

How to set a machine specific encryption to allow only one machine to decrypt data

From Dev

How to decrypt PHP Openssl encryption with BASH command

From Dev

How can I encrypt and decrypt using AES 128 without an IV?

From Dev

Using Apple NSKeyedArchiver class without encryption to save score data locally

From Dev

How to distribute a library which uses Closure-library without including any of the actual Closure-library source?

From Dev

Is it possible to decrypt one-way encryption? (with real data & encrypted data)

From Dev

Is it possible to decrypt one-way encryption? (with real data & encrypted data)

From Dev

How to use openssl to decrypt data encrypted by Java using AES

From Dev

How can we create our own string encoding-decoding or encryption-decryption script in java without using any given library i.e. Base64, AES, etc?

From Dev

java AES encryption then decrypt in PHP using same Key and IV

From Dev

Unable to decrypt config property in Spring Cloud config using asymmetric encryption

From Dev

How to decrypt HTTPS (ECDHE) data?

From Dev

How to encrypt large data in C++ using RSA encryption

From Dev

How to encrypt large data in C++ using RSA encryption

From Dev

How do I code a data encryption program using Python?

From Dev

How to decrypt using Blowfish in Pycrypto?

From Dev

How to decrypt with CryptoJS using AES?

From Dev

How to decrypt AES using PHP?

From Dev

Encrypt data using CryptoJS and decrypt using AESCipherService

From Dev

Access column of matrix without creating copy of data, using Armadillo library

From Dev

How to post JSON data using volley library?

Related Related

  1. 1

    How to decode/decrypt MD5 encryption using Java

  2. 2

    How to decrypt simple XOR encryption

  3. 3

    How to decrypt simple XOR encryption

  4. 4

    How to decrypt data using the BouncyCastle Blowfish implementation?

  5. 5

    How to decrypt data using the BouncyCastle Blowfish implementation?

  6. 6

    How to paginate data from server without using library in recyclerview?

  7. 7

    How to decrypt with WinRT without changing existing encryption code in .NET Desktop App?

  8. 8

    Encrypt / Decrypt UIImage in Swift using AES Encryption

  9. 9

    How to set a machine specific encryption to allow only one machine to decrypt data

  10. 10

    How to decrypt PHP Openssl encryption with BASH command

  11. 11

    How can I encrypt and decrypt using AES 128 without an IV?

  12. 12

    Using Apple NSKeyedArchiver class without encryption to save score data locally

  13. 13

    How to distribute a library which uses Closure-library without including any of the actual Closure-library source?

  14. 14

    Is it possible to decrypt one-way encryption? (with real data & encrypted data)

  15. 15

    Is it possible to decrypt one-way encryption? (with real data & encrypted data)

  16. 16

    How to use openssl to decrypt data encrypted by Java using AES

  17. 17

    How can we create our own string encoding-decoding or encryption-decryption script in java without using any given library i.e. Base64, AES, etc?

  18. 18

    java AES encryption then decrypt in PHP using same Key and IV

  19. 19

    Unable to decrypt config property in Spring Cloud config using asymmetric encryption

  20. 20

    How to decrypt HTTPS (ECDHE) data?

  21. 21

    How to encrypt large data in C++ using RSA encryption

  22. 22

    How to encrypt large data in C++ using RSA encryption

  23. 23

    How do I code a data encryption program using Python?

  24. 24

    How to decrypt using Blowfish in Pycrypto?

  25. 25

    How to decrypt with CryptoJS using AES?

  26. 26

    How to decrypt AES using PHP?

  27. 27

    Encrypt data using CryptoJS and decrypt using AESCipherService

  28. 28

    Access column of matrix without creating copy of data, using Armadillo library

  29. 29

    How to post JSON data using volley library?

HotTag

Archive