小编Mar*_*vic的帖子

与Webpack捆绑时,Underscore会出错

我试图重写使用require.js使用es6导入的旧应用程序.其中一个使用的库是Backbone和Underscore.要创建一个大包并将es6预编译到es5,我使用带有babel-loader的Webpack.Bundle被创建,但当我在浏览器中加载它时,我收到以下错误:

Uncaught TypeError: Cannot read property '_' of undefined
Run Code Online (Sandbox Code Playgroud)

看起来Underscore中的'this'在创建的bundle.js中是未定义的,所以root._给了我错误.

// Baseline setup
// --------------

// Establish the root object, `window` in the browser, or `global` on   the server.
var root = this;

// Save the previous value of the `_` variable.
var previousUnderscore = root._;

// Establish the object that gets returned to break out of a loop   iteration.
var breaker = {}
Run Code Online (Sandbox Code Playgroud)

有谁遇到过同样的问题?

javascript underscore.js ecmascript-6 webpack

7
推荐指数
1
解决办法
3013
查看次数

使用密码短语的CBC Java AES

我想用Java用CBC加密实现256密钥AES。收件人以字符串'absnfjtyrufjdngjvhfgksdfrtifghkv'的形式向我发送了256位密码,使用以下openssl命令可以很好地工作:

 echo test | openssl enc  -aes-256-cbc -a -k 'absnfjtyrufjdngjvhfgksdfrtifghkv'
Run Code Online (Sandbox Code Playgroud)

base64格式的输出为:U2FsdGVkX1 / yA4J8T + i1M3IZS + TO / V29rBJNl2P88oI =

当我描述它时,它返回原始输入字符串:

 echo U2FsdGVkX1/yA4J8T+i1M3IZS+TO/V29rBJNl2P88oI= | openssl enc -d -aes-256-cbc -a -k 'absnfjtyrufjdngjvhfgksdfrtifghkv'     
Run Code Online (Sandbox Code Playgroud)

我的问题是我无法使我的加密工作在Java中并使用上述命令将其解密。我知道我的密钥应该使用我的密码生成。以下是我的代码示例,其中IV是随机生成的,而密钥是使用密码短语和随机盐生成的。

byte[] input = "test".getBytes();
String passphrase = "absnfjtyrufjdngjvhfgksdfrtifghkv";
int saltLength = 8; 

SecureRandom random = new SecureRandom();

//randomly generate salt
byte[] salt = new byte[saltLength];
random.nextBytes(salt);

// generating key from passphrase and salt
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec spec = new PBEKeySpec(passphrase.toCharArray(), salt, 1024, 256);
SecretKey key = …
Run Code Online (Sandbox Code Playgroud)

java encryption passwords aes cbc-mode

4
推荐指数
1
解决办法
3658
查看次数