HarmonyOS 鸿蒙Next rc4加解密是否有问题

发布于 1周前 作者 caililin 来自 鸿蒙OS

HarmonyOS 鸿蒙Next rc4加解密是否有问题

let encrypted: string = CryptoJS.RC4Drop.encrypt(‘hello world!!’, ‘secret key 123456’, drop).toString()
let decrypted: string = CryptoJS.RC4Drop.decrypt(encrypted, ‘secret key 123456’, drop).toString()
上面两个值分别是
encrypted:U2FsdGVkX1/B1tGLbYw4mkZl2LeFsOGWRpmTcgA=
decrypted:68656c6c6f20776f726c642121


let encrypted2: string = CryptoJS.RC4.encrypt(“哈哈哈哈哈哈哈哈”, “secret key 12345”).toString();
let decrypted2: string = CryptoJS.RC4.decrypt(encrypted2, “secret key 12345”).toString();
上面两个值分别是
encrypted2:U2FsdGVkX19ATd7PpSNj6xLVPVPUb6fgYoMspqIrqFa/ssiaf9iQug==
decrypted2:e59388e59388e59388e59388e59388e59388e59388e59388

let encrypted3: string = CryptoJS.RC4.encrypt("//5mswmYBEIOQP2DNxUUEQFFQeSInCJCi1oFPFDUahUrilcVq4IHtrTVaj1bDxSptagoICIip4CACFoKKiAKZBNyhyQ78/vzZnY2s5vd7G72mNnNDJ98wmRm3nvze7/v/M73ewT7iDkFNkyZ4jzZ4epU75A6Q5GPlSTH0VC4A4PbE5AHUDsQcgBkiR9mbkVABkASwABIYXAtER0GUKn+MEoJdEiBUkyggwAdUCD/DMmxzykre3bK+Xt7P/98fcxfpoU3SC38/aN", “secret key 12345”).toString();
let decrypted3: string = CryptoJS.RC4.decrypt(encrypted3, “secret key 12345”).toString();

上面两个值分别是

encrypted3:U2FsdGVkX19bpCTvR8p4U1T0AaBKON2pYUd0ZB4bY8VdltXrVKMNHWLDkrl4EHy5jMS4g2HkbRKVu1w71qcaIYGYgMADrAMvrW30pMgth7zmcToG+lbpAkvpLPCb1AdbNrWHtHePHxTttfRz/cXWyey8mPD7JDqnpTfsSuI4rs0pD2jdgJRhQAunC0IHfdyr5YrL8vwYVq+h74VH3+5ngqNdDL5ap98Bebu/nyymZej4FYmvYLjWMVFfFCHDrz8rtJKIyBjErd852AU4Irg/KRb8Co/yRFFZGJsrAI/p2QjaqRnBnpdDbdxCKrjrlxmuM21YTGY7BmkZj3VekLpTvo0FMkor1DtyvxYyasRjgl3ary2mAXe8PRppuQ==
decrypted3:

2f2f356d73776d594245494f515032444e78555545514646516553496e434a4369316f465046445561685572696c63567134494874725456616a3162447853707461676f494349697034434143466f4b4b69414b5a424e7968795137382f767a5a6e593273357664374737326d4e6e4e444a3938776d526d336e767a65372f762f4d37336577543769446b464e6b795a346a7a5a3465705537354136513547506c535448305643344134506245354148554473516367426b6952396d626b5641426b4153774142495958417445523047554b6e2b4d456f4a64456942556b7967677741645543442f444d6d787a796b726533624b2b587437502f393866637866706f5533534333382f614e

什么情况,完全对不上啊,5.0的鸿蒙next

2 回复
值是匹配的,因为他是16进制,可以转换一下
[@State](/user/State) encryptText: string = ""

build() { Column() { Text(this.encryptText) Text(‘RC4 encrypt’) .fontSize(20) .margin(20) .fontWeight(FontWeight.Bold) .onClick(() => { let encrypted: string = CryptoJS.RC4.encrypt(‘hello world!’, ‘secret key 12345’).toString(); this.encryptText = encrypted console.log("RC4 encrypt= " + encrypted); prompt.showToast({ message: ‘RC4 encrypt=’ + encrypted }) })

  Text('RC4 decrypt')
    .fontSize(20)
    .margin(20)
    .fontWeight(FontWeight.Bold)
    .onClick(() => {
      let decrypted: string = CryptoJS.RC4.decrypt(this.encryptText, "secret key 12345").toString(CryptoJS.enc.Utf8)
      console.log("RC4 decrypt= " + decrypted)
      prompt.showToast({ message: 'RC4 decrypt=' + decrypted })
    })
}

}

HarmonyOS 鸿蒙Next中的RC4加解密算法在技术上本身是可行的,但RC4算法因其密钥调度算法和伪随机数生成器的弱点,可能在安全性要求较高的场合存在风险。此外,具体的实现质量和环境配置也可能影响加密解密的性能和稳定性。如果在使用过程中遇到具体问题,建议详细检查算法实现和环境配置。如果问题依旧没法解决请加我微信,我的微信是itying888。

回到顶部