使用angular2中的cryptojs库加密文本 [英] encrypt the text using cryptojs library in angular2
本文介绍了使用angular2中的cryptojs库加密文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 cryptojs 库来加密密码文本并将数据发送到服务器。
但是我收到以下错误说,
I am using cryptojs library for encrypting password text and sending the data to server. But i am getting the following error saying,
Error TS2304: Cannot find name 'CryptoJS'.
我按以下方式安装了库: sudo npm install crypto-js
I installed the library in the following way: sudo npm install crypto-js
import 'crypto-js/crypto-js';
@Page({
templateUrl: 'build/pages/login/login.html'
})
export class LoginPage {
constructor(private nav: NavController, public http: Http) {
}
validateUser(fieldval, data){
let params = "{'ignoreAuthModule': 'ignoreAuthModule'}";
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append('Parameter', params);
let url = 'app/authentication';
let encrypted_password = Cryptojs.AES.encrypt(fieldval.password, CryptoJS.enc.Base64.parse(data.seed),{mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }).toString().replace(/\+/g, "-").replace(/\//g, '_');
let requestoptions = new RequestOptions({
method: RequestMethod.Post,
url: url,
headers: this.headers,
body: JSON.stringify(data)
})
let body = JSON.stringify(params);
this.http.post(url, body, headers)
.subscribe(
response => {
},
error => {
console.log(error.text());
}
);
}
logError(err) {
console.error('There was an error: ' + err);
}
}
推荐答案
我不知道这个编译错误发生在哪里,但你应该安装crypto-js库的类型:
I don't know where this compilation error occurs but you should install the typings for the crypto-js library:
typings install --ambient crypto-js
有关详细信息,请参阅此问题:
See this question for more details:
- How to import non-core npm modules in Angular 2 e.g. (to use an encryption library)?
这篇关于使用angular2中的cryptojs库加密文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文