Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

javascript - Using Crypto-JS in Google Apps Script - What is C.lib?

I would like to us Crypto-JS in Google Apps Script and have copied all source files into my project.

When trying to encrypt data with its AES, I can't get it to work because the following reference in aes.js is not valid in Google Apps Script:

var C_lib = C.lib;

This is my "JavaScript for Dummies" question (I am a JavaScript newbie) :-)

How can I reference and use C.lib with Google Apps Script? What is C.lib? I have not found any good information on Google and SO.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From core.js:

/**
 * Library namespace.
 */
var C_lib = C.lib = {};

It seems that every file from the package CryptoJS use it something like:

var C_lib = C.lib;
var WordArray = C_lib.WordArray;
var BlockCipher = C_lib.BlockCipher;

So, most probably you have to link core.js if you are using development version.

Example from CryptoJS 3.1

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script>
    var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");

    var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase");
</script>

works without any other links.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...