go标准库的学习-crypto/des
参考:https://studygolang.com/pkgdoc
导入方式:
import "crypto/des"
des包实现了DES标准和TDEA算法,参见U.S. Federal Information Processing Standards Publication 46-3。
Constants
const BlockSize =
DES字节块的大小。
type KeySizeError
type KeySizeError int
func (KeySizeError) Error
func (k KeySizeError) Error() string
func NewCipher
func NewCipher(key []byte) (cipher.Block, error)
创建并返回一个使用DES算法的cipher.Block接口。
它与的区别在于它的key最长只能为8字节,否则会报错,如:
key := []byte("example w")
就会报错:
panic: crypto/des: invalid key size
举例:
package main import (
"fmt"
"crypto/des"
) func main() {
key := []byte("examplew") desCipher, err := des.NewCipher(key)
if err != nil {
panic(err)
}
var inputData = []byte{0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34}
out := make([]byte, len(inputData))
desCipher.Encrypt(out, inputData)
fmt.Printf("Encrypted data : %#v\n", out) //Encrypted data : []byte{0xac, 0x53, 0x6b, 0xbd, 0x59, 0xc5, 0x82, 0x59, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} plain := make([]byte, len(inputData))
desCipher.Decrypt(plain, out)
fmt.Printf("Decrypted data : %#v\n", plain) //Decrypted data : []byte{0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
}
func NewTripleDESCipher
func NewTripleDESCipher(key []byte) (cipher.Block, error)
创建并返回一个使用TDEA算法的cipher.Block接口。
举例:
package main import (
"fmt"
"crypto/des"
) func main() {
ede2Key := []byte("example key 1234")
var tripleDESKey []byte
tripleDESKey = append(tripleDESKey, ede2Key[:]...)
tripleDESKey = append(tripleDESKey, ede2Key[:]...)
desCipher, err := des.NewTripleDESCipher(tripleDESKey)
if err != nil {
panic(err)
}
var inputData = []byte{0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34}
out := make([]byte, len(inputData))
desCipher.Encrypt(out, inputData)
fmt.Printf("Encrypted data : %#v\n", out) //Encrypted data : []byte{0x39, 0x9e, 0xbe, 0xa9, 0xc3, 0xfa, 0x77, 0x5e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} plain := make([]byte, len(inputData))
desCipher.Decrypt(plain, out)
fmt.Printf("Decrypted data : %#v\n", plain) //Decrypted data : []byte{0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
}
go标准库的学习-crypto/des的更多相关文章
- go标准库的学习-crypto/md5
参考:https://studygolang.com/pkgdoc 导入方式: import "crypto/md5" md5包实现了MD5哈希算法,参见RFC 1321. Con ...
- go标准库的学习-crypto/sha1
参考:https://studygolang.com/pkgdoc 导入方式: import "crypto/sha1" sha1包实现了SHA1哈希算法,参见RFC 3174. ...
- go标准库的学习-crypto/sha256
参考:https://studygolang.com/pkgdoc 导入方式: import "crypto/sha256" sha256包实现了SHA224和SHA256哈希算法 ...
- go标准库的学习-crypto/rand
参考:https://studygolang.com/pkgdoc 导入方式: import "crypto/rand" rand包实现了用于加解密的更安全的随机数生成器. Var ...
- go标准库的学习-crypto/aes
参考:https://studygolang.com/pkgdoc 导入方式: import "crypto/aes" aes包实现了AES加密算法,参见U.S. Federal ...
- go标准库的学习-net/http
参考:https://studygolang.com/pkgdoc 概念解释: request:用户请求的信息,用来解析用户的请求信息,包括post.get.cookie.url等信息 respons ...
- go标准库的学习-database/sql
参考:https://studygolang.com/pkgdoc 导入方式: import "database/sql" sql包提供了保证SQL或类SQL数据库的泛用接口. 使 ...
- python 标准库基础学习之开发工具部分1学习
#2个标准库模块放一起学习,这样减少占用地方和空间#标准库之compileall字节编译源文件import compileall,re,sys#作用是查找到python文件,并把它们编译成字节码表示, ...
- python calendar标准库基础学习
# -*- coding: utf-8 -*-# 作者:新手__author__ = 'Administrator'#标准库:日期时间基础学习:calendar:处理日期#例1import calen ...
随机推荐
- LeetCode-数组操作-Python<三>
上一篇:LeetCode链表相加-Python<二> 以前没怎么做过算法题,来来去去都是那些循环,所以先从数组简单题开始做. 这两天最大心得: 总在边界里考虑不周到,导致错误 做晕的时候, ...
- MVC 【Razor 视图引擎】基础操作 --页面跳转,传值,表单提交
ASPX 与 Razor 仅仅是视图不一样. 新建项目----ASP.NET MVC 4 Web 应用程序------选择模板(空).视图引擎(Razor ) 1.视图中 c# 代码 与 HT ...
- [javaEE] HTTP协议总结
OSI网络7层协议 物理层 ==> 数据链路层 ==> 网络层ip ==> 传输层 TCP UDP ==>会话层 ==>表示层 ==> 应用层 HTTP FTP S ...
- Linux常用基本命令:三剑客命令之-awk输入输出分隔符
输入分隔符,英文原文为field separator,此处简称为FS,默认是空白字符(即空格),awk默认以空白字符为分隔符对每一行进行分割. 输出分割符,英文原文为output field sepa ...
- Bootstrap 、AngularJs
SPA 全称:single-page application单页面应用 说明:类似原生客户端软件更流畅的用户体验的页面.所有的资源都是按需加载到页面上. JSR 全称:Java Specificati ...
- create pdf file using Spire.Pdf or iTextSharp or PdfSharp
Spire.Pdf: 注:pdf 显示中文一定要设置相应的中文字体,其他外文类似.否则显示为乱码( 如果繁体的服务器上生成的中文内容PDF文档,在简体操作系统保存或并传给简体系统上查看,会存在乱码问题 ...
- 【读书笔记】iOS-iOS的UI自动化测试
1,Instruments iOS自带的自动化测试工具. 2,TuneupJs 最早的iOS自动化测试工具 https://github.com/alexvollmer/tuneup_js 3,yn ...
- IIS http 错误 401.3 - unauthorized
iis http 错误 401.3 - unauthorized 向物理目录添加iis_iusrs用户权限.
- 动态切换 web 报表中的统计图类型
统计图在浏览器端展现时,不同的使用人员对图形的展现形式会有不同的要求,有的需要柱形图.有的想看折线图等,报表支持用户在浏览器端动态的选择统计图类型,关注乾学院,查看具体实现方法动态切换 web 报表中 ...
- Runtime消息动态解析与转发流程
先上图: 下面根据具体代码看这张图. 一.创建一个Person类, Person.h #import <Foundation/Foundation.h> @interface Person ...