简体   繁体   English

无法使用ionic3应用程序中的crypto-js解密crypto-js中的加密值

[英]Unable to decrypt the encrypted value in crypto-js using crypto-js in ionic3 app

-I have successfully carried out the encryption part of the username and -- -password value using crypto-js in the ionic v3 app for capturing it into -firebase-analytics. -我已经成功使用ionic v3应用程序中的crypto-js对用户名和--password值进行了加密,以将其捕获到-firebase-analytics中。

import { Component, Input } from "@angular/core";

class Model {
    param1: string;
    value:any;
    myPassword = "my message 123";


function decrypt(this.someuservalue:any,this.somemailid:any){
const encrypted = CryptoJS.AES.encrypt(this.someuservalue,
 myPassword).toString();
}

}

-have obtained encrypted values in the firebase database as well. -也已在firebase数据库中获得了加密的值。

-But now to decrypt it in another independent javascript file I'm not able to do it. -但是现在要将其解密到另一个独立的javascript文件中,我将无法执行此操作。 -Here is how I'm trying to decrypt it -这就是我要解密的方式

var decrypted = CryptoJS.AES.decrypt(cipher, value);
var plaintext = = decrypted.toString(CryptoJS.enc.Utf8);

-But I'm unable to do so, -Any help can be greatly appreciated. -但我无法这样做,-任何帮助都将不胜感激。

-Thanks, -谢谢,

-I've tried -我试过了

var cipher = "encrypted value from the above implemented encryption"
password = "my message 123";

var rawData = atob(cipher);
    var iv = btoa(rawData.substring(0,16));
    var crypttext = btoa(rawData.substring(16));
    var plaintextArray = CryptoJS.AES.decrypt(
 {
    ciphertext: CryptoJS.enc.Base64.parse(crypttext),
    salt: ""
  },
  CryptoJS.enc.Hex.parse(password),
  { iv: CryptoJS.enc.Base64.parse(iv) }
);

-and -和

var bytes = CryptoJS.AES.decrypt({
ciphertext: CryptoJS.enc.Utf8.parse(cipher)
}, password, {format: CryptoJS.format.Utf8 });
var plaintext = bytes.toString();


-both didn't seem to work. -两者似乎都不起作用。

Take a look at Sodium (libsodium.js). 看一下 (libsodium.js)。

Sodium is a modern, easy-to-use software library for encryption, decryption, signatures, password hashing and more. 钠是一种现代,易于使用的软件库,用于加密,解密,签名,密码哈希等等。

It is a portable, cross-compilable, installable, packageable fork of NaCl, with a compatible API, and an extended API to improve usability even further. 它是NaCl的便携式,可交叉编译,可安装,可打包的分支,具有兼容的API和扩展的API,以进一步提高可用性。

Its goal is to provide all of the core operations needed to build higher-level cryptographic tools. 其目标是提供构建高级加密工具所需的所有核心操作。

Sodium is cross-platforms and cross-languages. 钠是跨平台和跨语言的。 It runs on a variety of compilers and operating systems, including Windows (with MinGW or Visual Studio, x86 and x86_64), iOS and Android. 它可以在各种编译器和操作系统上运行,包括Windows(使用MinGW或Visual Studio,x86和x86_64),iOS和Android。 Javascript and WebAssembly versions are also available and are fully supported. 也提供Javascript和WebAssembly版本,并且完全支持。 Bindings for all common programming languages are available and well-supported. 所有常用编程语言的绑定均可用并得到良好的支持。

The design choices emphasize security and ease of use. 设计选择强调安全性和易用性。 But despite the emphasis on high security, primitives are faster across-the-board than most implementations. 但是,尽管强调了高安全性,但与大多数实现相比,原语在整体上更快。

Version 1.0.17 was released on January 7, 2019. 版本1.0.17已于2019年1月7日发布。

Ref: 参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM