本文介绍了如何使cryptojs与“汇总"一起使用?档案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试升级旧版本的cryptoJS,该版本可以找到到github上的新版本,可在此处,因为旧版本中有一些功能将被弃用.不幸的是,较新的版本没有汇总文件,因此我试图使用核心文件使其正常工作,但是,我不断收到错误消息,例如" cfg.hasher未定义".

I'm trying to upgrade the old version of cryptoJS that can be found here to a newer version on github that can be found here because, there are some functions on the old version that is going to be deprecated. Unfortunately, the newer don't have rollup files, so im trying to get it to work using the core files but, I keep getting the error(s) that something is "undefined" like "cfg.hasher is undefined".

<script type="text/javascript" src="crypto-js3.1.9-1/core.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/evpkdf.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/x64-core.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/cipher-core.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/aes.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/pbkdf2.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/hmac.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/lib-typedarrays.js"></script>
<script type="text/javascript" src="crypto-js3.1.9-1/format-hex.js"></script>

我尝试添加所有核心文件,甚至更改它们的顺序,但我认为我仍然缺少一些东西.

I tried adding all the core files and even changing the orders of them, but I think I'm still missing something.

如果我使用汇总文件,则下面的简单代码可以很好地工作,但是在较新的版本上失败.希望有更多使用cryptoJS经验的人可以帮助我.

If I use the rollup files, this simple code below works just fine on it, but it fail on the newer version. Hopefully someone with more experience with cryptoJS can help me out.

<script type="text/javascript">
    var string = "asdfasdfsadfdsa";
    var key = "asdfasfasfs";
    var encrypted = CryptoJS.AES.encrypt(string, key);
    var decrypted = CryptoJS.AES.decrypt(encrypted, key);
    alert(decrypted);
</script>


更新!!我可以使SHA256在不使用require.js的情况下也能正常工作,所以我认为问题不在于模块化包含,并且库应该能够无需RequireJS"运行,但是我仍然遇到加密和解密错误:"cfg.hasher未定义".


UPDATE!! I can get SHA256 to work just fine with out uses of require.js so I don't thing the problem is Modular include and the lib should be able to run "without RequireJS", but I'm still running into encryption and decryption error: "cfg.hasher is undefined".

<script type="text/javascript" src="CryptoJS/components/core.js"></script>
<script type="text/javascript" src="CryptoJS/components/sha256.js"></script>
<script type="text/javascript">
    console.log(CryptoJS.SHA256("Message"));
</script>

推荐答案

您将不得不进行模块化包含

You would have to do modular includes

使用require js进行模块化包含:

Modular include using require js:

require.config({
    packages: [
        {
            name: 'crypto-js',
            location: 'path-to/bower_components/crypto-js',
            main: 'index'
        }
    ]
});

require(["crypto-js/aes", "crypto-js/sha256"], function (AES, SHA256) {
    console.log(SHA256("Message"));
});

这里是一个完整的要旨

这篇关于如何使cryptojs与“汇总"一起使用?档案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 09:22