import { decrypt, encrypt } from "@dm/crypto-wasm"; import { encrypt as sm4Encrypt } from "./sm4"; /** 与 sm-crypto@0.4.0 + crypto-js@4.2.0(ECB/PKCS#7、密钥见 sm4.js)对同一段 UTF-8 明文应得到相同 Base64。 */ const plain = `{"username":"admin","password":"admin123","code":"40","uuid":"7e9d6dae9c6740c8864d91445b79741d","clientId":"ihF3cJj0Mxf0xYh9rUqrtcJs-f7iQMrF","clientSecret":"-hs4ENSrdMPGhJUxM3E4CogQaGGb_TCReB51KlWxklhJDP-Dkz5JgFTozeshWdqF1UFjKCOiKR--ny53tusqhw"}`; const validateText = "ryfanf2S7ADSCLhO1rCXLZxHYuPGMXJKJMdUfVzKTKGnsgdccIqABqviVPXsTAnKPWbqDBT0ceITDKfxWH+Aa9n+HPYwcabe1fGR3N0QhV/PI7p9mjLS1N+Sn1EWjrDbs78jPRFWCLRiOAFEmrSKTPaMX3u5zCq+F6Bwkg5S0KmmAwUEYnnL5STqRJpK+d86MRhKDQpNvzgkR4iJYXCBSi5SxtD7dH4uXtdOz/NlJZ7tPMYJ2BD83e2PzjTe2dxJlTx+cDAPfbruJOeivTNayiM3QevGtfbsJHRPy/Ge7dwyqcJSGVkcUiLvzkANBfiZ6YBUwSopYXY2aLKS5fIGWg==" const cipherWasm = encrypt(plain); const cipherJs = sm4Encrypt(plain); console.log("[align] wasm === sm-crypto:", cipherWasm === cipherJs); console.log("[hello-wasm] ciphertext (base64):", cipherWasm); console.log("[hello-wasm] validateText === cipherWasm:", validateText === cipherWasm); console.log("[hello-wasm] validateText === cipherJs:", validateText === cipherJs); const recovered = decrypt(cipherWasm); console.log("[hello-wasm] round-trip OK:", recovered === plain);