は、私は、次イオン2で私が行っているイオン2インポートライブラリ
をcrypto-jsを実装しようとしていますフォルダが./typings/global
this.CryptoJS
(すなわち
alert(this.CryptoJS)
)アプリのクラッシュを試すとすぐ
declare var require: any;
import * as CryptoJS from 'crypto-js';
...
private CryptoJS: any;
constructor() {
this.CryptoJS = require("crypto-js");
}
test() {
alert(this.CryptoJS);
}
:
は、私は、次のコードを試してみてください。
私はcrypto-js
ライブラリをインポートする方法が間違っています。誰でも助言できますか?
おかげ
UPDATE:this次
は、私が実行します。
>npm install --save @types/cryptojs npm WARN package.json [email protected] No repository field. npm WARN package.json [email protected] No README data npm WARN package.json [email protected] No license field. @types/[email protected] node_modules\@types\cryptojs
私はコードでCryptoJS
をインポートするにはどうすればよいですか?
おかげ
UPDATE:
:に変更:
import { Injectable } from "@angular/core";
import { LanguageModel } from './languageModel';
import { LocationModel } from './locationModel';
import { JobModel } from './jobModel';
import 'crypto-js';
@Injectable()
export class PersonModel {
public id: number = null;
public joiningDate: number = null;
public lastAccessDate: number = null;
public userName: string = null;
public password: string = null;
public firstName: string = null;
public lastName: string = null;
public emailAddress: string = null;
public locations: LocationModel[] = [];
public languages: LanguageModel[] = [];
public time: string = null;
public avatar: string = null;
public avatar64: string = null;
//private CryptoJS: any;
private SECERET_KEY: string = 'secret key 123';
public getPasswordEcrypted(): string {
// Decrypt
var bytes = CryptoJS.AES.decrypt(this.password.toString(), this.SECERET_KEY);
var plaintext = bytes.toString(CryptoJS.enc.Utf8);
console.log('getPasswordEcrypted', plaintext);
return plaintext;
}
public setPasswordEncrypted(password: string): void {
// Encrypt
alert(password);
console.log('setPasswordEncrypted', password, CryptoJS);
alert(CryptoJS);
var ciphertext = CryptoJS.AES.encrypt(password, this.SECERET_KEY);
alert(ciphertext);
console.log('setPasswordEncrypted', password, ciphertext);
this.password = ciphertext;
}
}
UPDATE
UPDATE:
は、この実行:中の
結果CryptoJS
がアクセスされたときにビルドエラーに
typings install dt~crypto-js --global --save
結果を、しかし、実行時に(例えば、 console.log(CryptoJS);
)、アプリがクラッシュします。
これは進歩していると思われます。https://www.npmjs.com/package/@types/cryptojs – Richard
SECRET_KEYの取得先を教えてください。 プライベートSECERET_KEY:文字列= '秘密キー123'; ユーザー定義ですか? –