locked
Decrypting AES/ECB data

    Question

  • I'm trying to decrypt some data I'm receiving through HttpClient.

    The data is encrypted using AES/ECB with a single synchronous key and padded using PKCS#5.

    Currently i'm trying -

    function decryptBlob(blob) {
        var Crypto = Windows.Security.Cryptography;
        var key = "M02cnQ52Ji97wvT7";
    
        var SAP = Crypto.Core.SymmetricKeyAlgorithmProvider.openAlgorithm("AES_ECB_PKCS7");
        var bufferedKey = Crypto.CryptographicBuffer.convertStringToBinary(key, Crypto.BinaryStringEncoding.Utf8)
        var AES = SAP.createSymmetricKey(bufferedKey);
        var data = Crypto.CryptographicBuffer.convertFromBase64String(blob);
    
        var iBuffer = Crypto.Core.CryptographicEngine.decrypt(AES, data, null);
    }

    But this gives me the error :

    0x80090005 - JavaScript runtime error: Bad Data.In the function call:

    var data = Crypto.CryptographicBuffer.decodeFromBase64String(blob);

    Any ideas of what errors i'm making or how i'm going about this wrong?

    Monday, December 30, 2013 7:44 PM

Answers

  • Hi Brad,

    Can you validate your blob data? See the remark section of DecodeFromBase64String | decodeFromBase64String method:

    Base64 processes data as 24-bit groups, mapping each group to four encoded 8-bit characters. Base64 encoding is sometimes referred to as 3-to-4 encoding. Each 6 bits of the 24-bit group is used as an index into a mapping table (the base64 alphabet) to obtain a character for the encoded data.

    If your blob value is not a validated Base64 format, there is a big chance to throw Bad Data exception.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, December 31, 2013 5:49 AM
    Moderator