我正在尝试使用crypto.js创建一个应用程序,我可以在其中将纯文本转换为密文。我的逻辑如下所示
$scope.encrypt = function () {
if ($scope.message != '' && $scope.passphrase != '' ) {
alert('clicked');
$scope.cypher = CryptoJS.AES.encrypt($scope.message, $scope.passphrase);
$scope.cypherString = String($scope.cypher);
$scope.message = '';
$scope.feedBack = 'The text was successfully encrypted.';
$scope.status = 'success';
} else {
$scope.feedBack = 'You need to enter a key phrase to encrypt text.';
$scope.status = 'error';
}
}
但即使我输入两个字段我都无法获得加密消息我总是看到错误消息..下面是plnkr的链接 http://plnkr.co/edit/3g1N09?p=preview
答案 0 :(得分:0)
更改此功能:
$scope.encrypt = function (message,passphrase) {
if (message && passphrase ) {
alert('clicked');
$scope.cypher = CryptoJS.AES.encrypt(message, passphrase);
对此的看法:
<button class="button button-block button-balanced" ng-click="encrypt(message,passphrase)" >
并删除$ scope.message =&#39;&#39; assignements ...