简体   繁体   English

如何在不使用Chilcat库的情况下解密使用Chilkat进行加密的数据

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

We have a Windows Phone 8 app that needs to communicate with a web service that uses Chilkat to encrypt some data. 我们有一个Windows Phone 8应用,该应用需要与使用Chilkat加密某些数据的Web服务进行通信。 As far as I know, Chilkat does not support the Windows Phone platform. 据我所知,Chilkat不支持Windows Phone平台。 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? 我有关于如何加密数据的密钥和其他信息(例如加密算法名称,密钥长度等),但是我可以在没有此库的情况下在Windows Phone上进行加密/解密吗? (We already have android/ios apps that use the same service and they use the chilkat library to crypt the data) (我们已经有使用相同服务的android / ios应用程序,它们使用chilkat库来加密数据)

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);
    }
}

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? 我有关于如何加密数据的密钥和其他信息(例如加密算法名称,密钥长度等),但是我可以在没有此库的情况下在Windows Phone上进行加密/解密吗?

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. 如果它们使用经过审查的库构成的知名算法, 并且已完全指定了算法和参数,则答案可能是肯定的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Chilkat:如何解密加密的 email? - Chilkat : How to decrypt an encrypted email? 如何使用XML加密语法和处理规范来解密存储在XML中的数据? - How can I decrypt data stored in XML using the XML Encryption Syntax and Processing spec? 如何使用chilkat组件获取网站的HTML? - How to get HTML of website using chilkat component? 使用chilkat库进行压缩/解压缩时遇到一些问题 - Having some issues while using chilkat library for zipping/unzipping 如何在不更改.NET Desktop App中现有加密代码的情况下使用WinRT解密? - How to decrypt with WinRT without changing existing encryption code in .NET Desktop App? 加密后如何解密存储的xml元素 - how to decrypt xml elements stored after encryption 如何将 CspParameters 传递给另一个 RSACryptoServiceProvider 进行加密和解密 - How to pass CspParameters to another RSACryptoServiceProvider to encryption and Decrypt it 使用Chilkat 3DES提供程序进行加密,并使用标准.NET提供程序进行相同的结果 - Encryption using Chilkat 3DES provider and the same result using standard .NET provider 在ASP.NET C#中使用AES加密时,要解密的数据长度无效 - Length of the data to decrypt is invalid when using AES encryption in ASP.NET C# 如何使用 BouncyCastle Blowfish 实现解密数据? - How to decrypt data using the BouncyCastle Blowfish implementation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM