1 Star 0 Fork 0

彭明/dm

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
zzc.go 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
彭明 提交于 2024-04-10 13:53 +08:00 . DmDMS first init
/*
* Copyright (c) 2000-2018, 达梦数据库有限公司.
* All rights reserved.
*/
// go官方没有实现ecb加密模式
package security
import (
"crypto/cipher"
)
type ecb struct {
b cipher.Block
blockSize int
}
func newECB(b cipher.Block) *ecb {
return &ecb{
b: b,
blockSize: b.BlockSize(),
}
}
type ecbEncrypter ecb
func NewECBEncrypter(b cipher.Block) cipher.BlockMode {
return (*ecbEncrypter)(newECB(b))
}
func (x *ecbEncrypter) BlockSize() int { return x.blockSize }
func (x *ecbEncrypter) CryptBlocks(dst, src []byte) {
if len(src)%x.blockSize != 0 {
panic("dm/security: input not full blocks")
}
if len(dst) < len(src) {
panic("dm/security: output smaller than input")
}
if InexactOverlap(dst[:len(src)], src) {
panic("dm/security: invalid buffer overlap")
}
for bs, be := 0, x.blockSize; bs < len(src); bs, be = bs+x.blockSize, be+x.blockSize {
x.b.Encrypt(dst[bs:be], src[bs:be])
}
}
type ecbDecrypter ecb
func NewECBDecrypter(b cipher.Block) cipher.BlockMode {
return (*ecbDecrypter)(newECB(b))
}
func (x *ecbDecrypter) BlockSize() int { return x.blockSize }
func (x *ecbDecrypter) CryptBlocks(dst, src []byte) {
if len(src)%x.blockSize != 0 {
panic("dm/security: input not full blocks")
}
if len(dst) < len(src) {
panic("dm/security: output smaller than input")
}
if InexactOverlap(dst[:len(src)], src) {
panic("dm/security: invalid buffer overlap")
}
for bs, be := 0, x.blockSize; bs < len(src); bs, be = bs+x.blockSize, be+x.blockSize {
x.b.Decrypt(dst[bs:be], src[bs:be])
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/sitkcn/dm.git
git@gitee.com:sitkcn/dm.git
sitkcn
dm
dm
v0.0.1

搜索帮助