Archived Forum Post

Index of archived forum posts

Question:

How we can traslate this java decoding in ChilKat's Crypt

Jun 06 '14 at 07:59

Hi to All! How we can traslate this code 'to speak' with asp ?

thanks, bajo.

String doDecode(String password, String text) throws Exception { SecretKey key = getKey(password);

        //IMPORTANT TO GET SAME RESULTS ON iOS and ANDROID
        final byte[] iv = new byte[16];
        Arrays.fill(iv, (byte) 0x00);
        IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);

        byte[] encrypedPwdBytes = Base64.decode(text, Base64.DEFAULT);
        // cipher is not thread safe
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
        cipher.init(Cipher.DECRYPT_MODE, key, ivParameterSpec);
        byte[] decrypedValueBytes = (cipher.doFinal(encrypedPwdBytes));

        String decrypedValue = new String(decrypedValueBytes);
        LogHelpers.DebugLog("Decrypted: " + text + " -> " + decrypedValue);
        return decrypedValue;

Answer

It would be something like this:

set crypt = Server.CreateObject("Chilkat_9_5_0.Crypt2")

success = crypt.UnlockComponent("Anything for 30-day trial")

crypt.CryptAlgorithm = "aes" crypt.CipherMode = "cbc" ' Set the key length to 128 or 256, depending on your key size. crypt.KeyLength = 256

' 0 = PKCS7Padding crypt.PaddingScheme = 0

crypt.EncodingMode = "base64"

ivHex = "00000000000000000000000000000000" crypt.SetEncodedIV ivHex,"hex"

' We have 32 bytes here for a 256-bit key keyHex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" crypt.SetEncodedKey keyHex,"hex"

decryptedStr = crypt.DecryptStringENC(encryptedBase64Str)

The challenge is to make sure you set the exact same binary key. Your code snippet above transforms a password string to the exact binary secret key via the getKey(password) call. You would need to know the exact algorithm/transformation that is used to transform from a password string to a 16-bit or 32-byte key, and this would need to be duplicated in the ASP code..