Giter VIP home page Giter VIP logo

Comments (6)

lpilp avatar lpilp commented on August 14, 2024

你用的哪个go的库,我试试 或者你把go加密的结果打出来看看

from phpsm2sm3sm4.

yimingren30 avatar yimingren30 commented on August 14, 2024

https://github.com/tjfoc/gmsm

在您的文档里看到这个关于 golang的 ,在 php 和 golang 中使用相同的 key 和 iv 。
在golang中解密原始数据,解密也能获取到原始数据
使用 php 生成的串,使用 golang 解密失败

=== RUN TestSm4
sm_test.go:24: u�6���Ƿ�eW�g�R�
sm_test.go:26: 123456
sm_test.go:29:

from phpsm2sm3sm4.

lpilp avatar lpilp commented on August 14, 2024

输入输出的格式不一样呢, 我这个加密输出是hex的, 解密输入也是 hex, go那个输入输出是 byte[], 相当于是bin格式, 你得格式转换下,PHP这个应该没有什么问题 ,与openssl(新版本openssl就支持sm4了) 算出来的是一样的,

from phpsm2sm3sm4.

yimingren30 avatar yimingren30 commented on August 14, 2024

大佬 golang 版本的有 https://github.com/tjfoc/gmsm 使用例子吗 ,结合 php 加解密

from phpsm2sm3sm4.

lpilp avatar lpilp commented on August 14, 2024

没有,他那个项目里有一个sm4Test.go 文件,你按那个用法就行, 生成的不一样,可以转一下格式
对接双方用什么语言都无所谓,只要最后统一成一个格式就行

func hexStringToByte(hex string) []byte {
    h, err := hex.DecodeString(hex)
    if err != nil {
        log.Fatalf("hexStringToByte: %s", err)
    }
    return h
}

go的 hex转 []byte

from phpsm2sm3sm4.

yimingren30 avatar yimingren30 commented on August 14, 2024

好的 谢谢喽

from phpsm2sm3sm4.

Related Issues (20)

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.