Skip to main content
Hello all,

I have an aura component where I need to encrpty a string that contains vlaues from the component.  Can I do this within the component JS?  Or does the data need to be sent to a controller and then pulled back again?  I am encrypting  a string and sending it to an external site when a user saves their record.

Thank you,

P
답변 3개
  1. 2022년 4월 8일 오후 9:25

    https://cryptojs.gitbook.io/docs/

     

    Static Resource Detail

    Name cryptojs

    Namespace Prefix

    Description

    MIME Type text/javascript

    Cache Control Private

    Size 48 316 bytes

     

    <aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome" access="global" >

    <ltng:require

    scripts="{!$Resource.cryptojs}"

    afterScriptsLoaded="{!c.scriptsLoaded}" />

    <h1>Crypto Lex</h1>

    </aura:component>

     

    ({

    scriptsLoaded : function(component, event, helper) {

    var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");

    console.log('> encrypted:' + encrypted);

    var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase").toString(CryptoJS.enc.Utf8);

    console.log('> decrypted:' + decrypted);

    }

    })

    > encrypted:U2FsdGVkX1/JqGDagBEnmRXSuDmYb5MNL7Kuo4xT+gk=  ( "Message" encoded )

    > decrypted:Message  (ok)

     
0/9000