Exemplo n.º 1
0
        private static string Decrypt(JvResponse jvResponse)
        {
            RSACryptoServiceProvider rSA = GetPrivateKeyFromDerFile();

            byte[] keyArr = rSA.Decrypt(Convert.FromBase64String(jvResponse.key), RSAEncryptionPadding.Pkcs1);

            RijndaelManaged aesEncryption = new RijndaelManaged();

            aesEncryption.BlockSize = 128;
            aesEncryption.KeySize   = 256;

            aesEncryption.Mode    = CipherMode.ECB;
            aesEncryption.Padding = PaddingMode.None;


            byte[] KeyArr32BytesValue = new byte[32];
            Array.Copy(keyArr, KeyArr32BytesValue, 32);

            aesEncryption.Key = KeyArr32BytesValue;

            ICryptoTransform decrypto = aesEncryption.CreateDecryptor();

            byte[] encryptedBytes = Convert.FromBase64CharArray(jvResponse.payload.ToCharArray(), 0, jvResponse.payload.Length);
            byte[] decryptedData  = decrypto.TransformFinalBlock(encryptedBytes, 0, encryptedBytes.Length);
            return(System.Text.ASCIIEncoding.UTF8.GetString(decryptedData));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string jsonString = "{ \"filter\":{ \"task\":{ \"processInstanceId\":{ \"eq\":\"5fda297111edfb36b766c7871\" } } } }";
            String response   = EncryptStringToBytes(jsonString);

            JvResponse jvResponse = JsonSerializer.Deserialize <JvResponse>(response);

            Console.WriteLine(jvResponse.key);
            Console.WriteLine(jvResponse.payload);

            Console.WriteLine(Decrypt(jvResponse));
        }