Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...