Git Product home page Git Product logo

Comments (2)

luckykellan avatar luckykellan commented on August 15, 2024 1

Hutool的密文前面是04开头,需要将04去掉后使用dart_sm解密
同样,使用dart_sm.SM2加密后的密文,也需要手动增加04前缀后再使用Hutool解密

dart

  final keypair = SM2.generateKeyPair();
  final publicKey = keypair.publicKey; //041f46ff512b1091d59809565688ec76cff14e25740d63621ebdecbe9cdda294087239b67f210bcaf0aeae19e1158d7d3dc84d3be55e85a110611cba820ecca584
  final privateKey = keypair.privateKey; //a4751815dfcc307847632680f862d291f9284fb6b54aeb30c9450368ac53c0f5

java

 val sm2 = SmUtil.sm2("a4751815dfcc307847632680f862d291f9284fb6b54aeb30c9450368ac53c0f5","041f46ff512b1091d59809565688ec76cff14e25740d63621ebdecbe9cdda294087239b67f210bcaf0aeae19e1158d7d3dc84d3be55e85a110611cba820ecca584")
 val data = "123";
 val encrypt = sm2.encryptHex(data, KeyType.PublicKey) //04b6c1b407e82a865f733225c20b20d9cd6c15f2f57097f6bcce2e1a01c5a6edb6cc7046451103ced92f0982a82fa2dd0e567f313525de6dd9a541504b8f752796d99e3b7e1bb9198320c0c92926cf5aa6292907c8a4d85e61ecbeda5c502578eb04c330

回到dart解密

 // 这里注意,如果密文前两位是04,需要把04删除后解密
 final cipherText = 'd57726870661ad2bd5aea0b56c532bfea83523b4747e9ae7a739186ba0c1ee040a4d4f92c46481119069b7dd43c6d774364feb74100b497fbc0a64f58720d8ebbf0e81c4b3b647d29299d3fa43b190798060fbae88a2b5809bb72c82626e587ec1da8a';
 final plainText = SM2.decrypt(cipherText, privateKey2);
 print("plainText: $plainText"); //123

from dart_sm.

esummer avatar esummer commented on August 15, 2024

感谢大佬,问题解决。

from dart_sm.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.