惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Archives - TechRepublic
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
Cisco Talos Blog
Cisco Talos Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
S
Secure Thoughts
H
Hacker News: Front Page
I
Intezer
Cyberwarzone
Cyberwarzone
T
Tor Project blog
The Last Watchdog
The Last Watchdog
Google DeepMind News
Google DeepMind News
T
Threatpost
T
Tenable Blog
NISL@THU
NISL@THU
AWS News Blog
AWS News Blog
阮一峰的网络日志
阮一峰的网络日志
T
Troy Hunt's Blog
E
Exploit-DB.com RSS Feed
V
Visual Studio Blog
W
WeLiveSecurity
腾讯CDC
The GitHub Blog
The GitHub Blog
T
The Exploit Database - CXSecurity.com
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
V2EX - 技术
A
Arctic Wolf
N
Netflix TechBlog - Medium
S
Securelist
WordPress大学
WordPress大学
Schneier on Security
Schneier on Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
AI
AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
B
Blog
Apple Machine Learning Research
Apple Machine Learning Research
Help Net Security
Help Net Security
Google Online Security Blog
Google Online Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
G
Google Developers Blog
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cloudbric
Cloudbric
P
Palo Alto Networks Blog

PHP

有没有什么好用的免费开源 CRM 系统 - V2EX 2026 年 PHP 路在何方 - V2EX 2026 年,学 laravel 有没有前途: - V2EX 有没有这样的 PHP 框架 - V2EX PHP 是不是快死了 - V2EX php74-fpm 加 nginx, PHP 文件只要不是 root /var/www/html 就提示 No input file specified.求大佬看看 - V2EX PHP framewok 框架推荐 - V2EX 基于 yii2 框架开发的后台管理软件,免费 - V2EX 「一键部署你的专属服务器」——WNMP 一键包,让 Web 环境搭建回归简单 - V2EX 完蛋了,为什么我感觉 PHP 的语法这么优雅呢 - V2EX 未来属于 PHP - V2EX 记一次微信 access_token invalid credential, access_token is invalid or not latest - V2EX 重造 PHP -HTTP 性能检测,新增 List<int>、HashMap<K, V> - V2EX 求助: PHP 错误,请高手帮我改写下面的 PHP 代码 - V2EX 为什么现在 WEB3、区块链、钱包之类开始用 PHP 了 - V2EX PHP 8.5 加入了 pipe 语法 - V2EX 推荐一个优雅的 PHP http 请求工具,仿照了 py 的 requests - V2EX 大家好,我又來了,新作品 https://www.freetalkhub.com, PHP 开发 - V2EX laravel 和 thinkphp 选择哪个? - V2EX 202505 最新调研: PHP Opcode 加密混淆哪家强? - V2EX 有做过基于 webrtc 技术的多人视频会议系统的吗 - V2EX 2025 年 PHP 路在何方 - V2EX 求助 CodeIgniter 输出的 html 格式很乱,缩进乱七八糟的。。。 - V2EX 有个关于 PHP 的小疑惑 - V2EX workman 与阿里云实时语音通信的问题。 - V2EX 目前 PHP 中比较好用的工作流引擎有哪些? - V2EX 有老哥熟悉 OpenCart 的吗? - V2EX 开源 PHP Composer 私有 package 管理平台 - V2EX 推荐个好用的集成环境 - V2EX phpinfo(); logo 变成了绿色的大象 - V2EX PHP 项目有类似前端 monorepo 的概念吗? 想用 PHP 做微服务开发,有偿求指导 - V2EX PHP 语言已经过气了吗 - V2EX 国内 PHP 卷王是鸟哥 mysql update 更新失败的原因。 - V2EX PHP 程序员是往运维还是前端发展作为拓展呢 - V2EX 求大佬解决一下一个问题 - V2EX [2024-11-21] PHP 8.4 Released! - V2EX 如何获得抖音视频播放量?各位大牛支支招~ 如何优雅地切换 composer 镜像 - V2EX Laravel 二手项目,语言切换问题,求解 两道 PHP 题目,都是求 flag 值 帮忙推荐一个开源论坛源码? Laravel 完成了 A 轮融资🎉 PHP 虽然没落了,但是 PHP 的东西是真的好用 世界上最好的 serverless 平台! imgur 是怎么做到一个链接新窗口打开 302,但是还能作为图片显示的? PHP 编译器 BPC 编译 ThinkPHP8 + PHPUnit 测试 的视频来了
与银行对接 sm4 国密算法 - V2EX
cbasil · 2024-10-31 · via PHP
cbasil

14

cbasil      2024 年 10 月 31 日

@ca2oh4 我当时也考虑用 golang 写一个脚本,然后 php 通过 http 调用。不过后面解决了就不用了。这是当时写的 golang 案例

```golang
package main

import (
"bytes"
"crypto/cipher"
"encoding/hex"
"fmt"

"github.com/tjfoc/gmsm/sm4"
)

// PKCS5Padding 使用 PKCS5 填充
func PKCS5Padding(src []byte, blockSize int) []byte {
padding := blockSize - len(src)%blockSize
padtext := bytes.Repeat([]byte{byte(padding)}, padding)
return append(src, padtext...)
}

// PKCS5UnPadding 去除 PKCS5 填充
func PKCS5UnPadding(src []byte) []byte {
length := len(src)
unpadding := int(src[length-1])
return src[:(length - unpadding)]
}

// SM4 CBC 模式加密
func sm4CBCEncrypt(key, plaintext, iv []byte) ([]byte, error) {
block, err := sm4.NewCipher(key)
if err != nil {
return nil, err
}

plaintext = PKCS5Padding(plaintext, block.BlockSize())
ciphertext := make([]byte, len(plaintext))
mode := cipher.NewCBCEncrypter(block, iv)
mode.CryptBlocks(ciphertext, plaintext)
return ciphertext, nil
}

// SM4 CBC 模式解密
func sm4CBCDecrypt(key, ciphertext, iv []byte) ([]byte, error) {
block, err := sm4.NewCipher(key)
if err != nil {
return nil, err
}

plaintext := make([]byte, len(ciphertext))
mode := cipher.NewCBCDecrypter(block, iv)
mode.CryptBlocks(plaintext, ciphertext)
plaintext = PKCS5UnPadding(plaintext)
return plaintext, nil
}

func main() {
key, _ := hex.DecodeString("key") // 16 字节的十六进制密钥
iv, _ := hex.DecodeString("iv") // 16 字节的 IV
plaintext := []byte("This is a secret message.")

// 加密
ciphertext, err := sm4CBCEncrypt(key, plaintext, iv)
if err != nil {
fmt.Println("Encryption error:", err)
return
}
fmt.Printf("Ciphertext (hex): %s\n", hex.EncodeToString(ciphertext))
// 解密
decrypted, err := sm4CBCDecrypt(key, ciphertext, iv)
if err != nil {
fmt.Println("Decryption error:", err)
return
}
fmt.Printf("Decrypted text: %s\n", decrypted)
}
```