package
0.0.0-20240821054911-366547e8a2d4
Repository: https://github.com/windzhu0514/go-utils.git
Documentation: pkg.go.dev

# README

crypto

go crypto library

加密算法

AES支持三种长度的密钥:128位,192位,256位,即AES128,AES192,AES256 AES256安全性最高 AES128性能最高

  • IV支持不传入值,默认生成且返回
  • 生成随机key,根据不同算法生成

IV

// 在除ECB以外的所有加密方式中,都需要用到IV对加密结果进行随机化。在使用同一种加密同一个密钥时不应该使用相同的IV,否则会失去一定甚至全部的安全性。

BlockMode

ECB 电码本模式 Electronic Codebook Book

ECB模式有一个显著的安全问题:如果使用相同的密钥, 那么相同的明文块就会生成相同的密文块,不能很好的隐藏数据模式,因此,在密码协议中不建议使用ECB模式

CBC 密码分组链接模式 Cipher Block Chaining

// BlockModeCBC CBC模式加密过程是串行的,不能并行化,速度比较慢,但是解密可以并行。另外,如果密文的某一位被修改了,只会使这个密文块所对应的明文块完全改变并且改变下一个明文块的对应位,安全性仍然有一定的欠缺。

CFB 密码反馈模式 Cipher FeedBack

CTR 计算器模式 Counter

OFB 输出反馈模式 Output FeedBack

参考资料:

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TODO:RSADecryptNoPadding RSA无填充私钥解密.
RSADecryptOAEP RSA私钥解密.
RSADecryptPKCS1v15 RSA私钥解密 支持长文本加密.
RSAEncryptNoPadding RSA无填充公钥加密.
RSAEncryptOAEP RSA RSAES-OAEP加密方案是RFC3447推荐新应用使用的标准, RSAES-PKCS1-v1_5 是为了与已存在的应用兼容,并且不建议用于新应用。 详细参考:https://www.rfc-editor.org/rfc/rfc3447.html#section-7.
RSAEncryptPKCS1v15 RSA公钥加密 支持长文本加密.
RSAPrivateEncrypt RSA私钥加密.
RSAPublicDecrypt RSA公钥解密.
gcm.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

CBC 密码块链模式(Cipher-block chaining) 每个明文块先与前一个密文块进行异或后,再进行加密。在这种方法中,每个密文块都依赖于它前面的所有平文块。 同时,为了保证每条消息的唯一性,在第一个块中需要使用初始化向量。 CBC是最为常用的工作模式。它的主要缺点在于加密过程是串行的,无法被并行化,而且消息必须被填充到块大小的整数倍。 加密时,平文中的微小改变会导致其后的全部密文块发生改变,而在解密时,从两个邻接的密文块中即可得到一个平文块。 因此,解密过程可以被并行化,而解密时,密文中一位的改变只会导致其对应的平文块完全改变和下一个平文块中对应位发生改变, 不会影响到其它平文的内容.
No description provided by the author
No description provided by the author
ECB 电子密码本模式(lectronic codebook) 最简单的模式,也是最不安全的模式。需要加密的消息按照块密码的块大小被分为数个块,并对每个块进行独立加密,相同明文会产生同样的密文组。 这会暴露明文数据的格式和统计特征,从而有潜在的安全风险,但是用于短数据(如加密密钥)时非常理想.
GCM AE,Authenticated Encryption.
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

AESCipher AES Advanced Encryption Standard 支持 ECB、CBC、CFB、CTR、GCM、OFB key 长度 16、24、32 位,即 128、192、256 bit(AES-128、AES-192、AES-256),位数越大安全性越高但加密速度越慢.
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author