Recently, there was a need to obtain the summary value of fast application, but it was found that the fast application specification did not provide the relevant interface. Fortunately, after some searching, I found that the third-party library crypto-js can be used to obtain it. The following is the way to obtain it.

Install dependencies

  1. Check whether there is a third-party library dependency file package.json in the Quick Application project directory. If not, Start the third-party dependencies in the Quickapp IDE: toolbar Npm->Start Npm Library. After this step, generate package.json file in the quickapp project root directory.

  2. Run NPM install: Toolbar NPM -> NPM install.

  3. Switch to the “Terminal” TAB under the IDE, enter the quick application project root directory, install the crypto-js library, enter the installation command: NPM i-S crypto-js, as shown below:

4. After installation, the dependency of Crypto-js will be automatically added to package.json file.

The code references

See the use of crypto-js in ES6, for example:

import sha256 from 'crypto-js/sha256';
import MD5  from 'crypto-js/md5';
  
genSha256: function (e) {
      const msg = this.testdata;
      this.sha256value = sha256(msg);
    },
    genMD5: function () {
      const msg = this.testdata;
      this.md5value = MD5(msg);
    },
Copy the code

For more details, see:

Crypto. Js development documentation: www.npmjs.com/package/cry…


The original link: developer.huawei.com/consumer/cn… Author: Chao Youting, Drum Tower