Triple DES decryption in classic ASP?

后端 未结 3 717
闹比i
闹比i 2021-01-06 07:44

How can I decrypt a string in classic-ASP/VBScript? The string comes from a php application that uses 3DES encryption.

3条回答
  •  北海茫月
    2021-01-06 08:03

    I have a Javascript implementation of DES/TripleDES. It does CBC and ECB modes, and for padding supports PKCS7, Spaces, or Zeroes. It's integrated with a RFC2898-compliant PBKDF2, so it can generate encryption keys and IV's from passwords if you like. You can also set the crypto key and IV explicitly.

    It is usable when calling directly from Javascript - any browser, or from Rhino, or WScript.exe, or maybe closer to your case, classic ASP using Javascript.

    I've also packaged it as a COM component, so it is possible to call it from any COM-compliant environment, like VBScript running in classic ASP, or Perl, or VBA, etc.

    It is an independent implementation, and is fully compliant with and interoperable with the .NET DESCryptoServiceProvider and TripleDESCryptoServiceProvider.

    Get it here: http://cheeso.members.winisp.net/srcview.aspx?dir=DES

    When calling it directly from Javascript, it looks like this:

    var pbkdf2 = new PBKDF2(password, salt, iterations);
    var key = pbkdf2.deriveBytes(8); // use 24 for 3DES
    var iv = pbkdf2.deriveBytes(8);  // always 8 (==blocksize)
    var des = new DES(key,iv);
    var plaintext = "Hello. This is a test. of the emergency broadcasting system.";
    var ciphertext = des.encrypt(plaintext);
    

    When calling the COM component from VBScript, it looks like this:

    Dim des
    set des = CreateObject("Ionic.Com.DES")
    des.Password = "This is my password"
    des.Mode = "CBC"
    des.TripleDES = True
    des.Rfc2898Iterations = 1000
    Dim result
    result = des.EncryptString(plainText)
    Dim decrypted
    decrypted = des.DecryptBytes(result)
    WScript.echo "decrypted       : " & decrypted
    

    The encryption is pretty fast but the key generation is not.


    Edit:

    you can also use the Javascript DES stuff in a browser.
    here's an example: http://jsbin.com/oguye3

提交回复
热议问题