Top
3DES Encryption with CFSCRIPT – Dragos Cirjan
fade
749
post-template-default,single,single-post,postid-749,single-format-standard,eltd-core-1.1.1,flow child-child-ver-1.0.0,flow-ver-1.3.6,,eltd-smooth-page-transitions,ajax,eltd-blog-installed,page-template-blog-standard,eltd-header-standard,eltd-fixed-on-scroll,eltd-default-mobile-header,eltd-sticky-up-mobile-header,eltd-dropdown-default,wpb-js-composer js-comp-ver-5.0.1,vc_responsive

Warning: A non-numeric value encountered in /usr/src/wordpress/wp-content/themes/flow/framework/modules/title/title-functions.php on line 417

3DES Encryption with CFSCRIPT

3DES Encryption with CFSCRIPT

Won’t comment much about it. We needed it, you may need it, so here it is:



    key = '62v01fVsCWHfRcW';
    text = '66866996699';
    iv = BinaryDecode("0000000000000000","hex");

    function extendKey(key, size = 24, c = "0") {
        var i = 0;
        for (i = len(key); i lt size; i = i + 1) {
            key = key & c;
        }
        return key;
    }
    
    function extendText(text, c = "0") {
        var i = 0;
        for (i = len(text) % 8; i lt 8; i = i + 1) {
            text = text & c;
        }
        return text;
    }
    
    function encrypt3desCbcCF(text, key, iv) {
        return encrypt(
            text, 
            toBase64(extendKey(key, 24, urlDecode('%00'))), 
            'DESEDE/CBC/PKCS5Padding', 
            'Base64', 
            iv
        );
    }
    
    function javaCreateObject(obj) {
        return createObject('java', obj);
    }
    
    function encrypt3desCbcJava(text, key, iv) {
        var Cipher          = javaCreateObject('javax.crypto.Cipher');
        var IvParameterSpec = javaCreateObject('javax.crypto.spec.IvParameterSpec');
        var SecretKeySpec   = javaCreateObject('javax.crypto.spec.SecretKeySpec');
    
        var jkey = SecretKeySpec.init(
            extendKey(key, 24, urlDecode('%00')).getBytes(), 
            "DESede"
        );

        var jiv = IvParameterSpec.init(iv);

        var jcipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
        jcipher.init(Cipher.ENCRYPT_MODE, jkey, jiv);
        
            
        return toBase64(jcipher.doFinal(
            text.getBytes()
        ));
    }







Check also as an example here on trycf.com

Cirjan Dragos
No Comments

Post a Comment