加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
encrypter.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2024-11-21 23:08 . 移除中文注释
package dongle
type Encrypter struct {
dongle
}
// newEncrypter returns a new Encrypter instance.
func newEncrypter() Encrypter {
return Encrypter{}
}
// FromString encrypts from string.
func (e Encrypter) FromString(s string) Encrypter {
e.src = string2bytes(s)
return e
}
// FromBytes encrypts from byte slice.
func (e Encrypter) FromBytes(b []byte) Encrypter {
e.src = b
return e
}
// String implements Stringer interface for Encrypter struct.
func (e Encrypter) String() string {
return e.ToRawString()
}
// ToRawString outputs as raw string without encoding.
func (e Encrypter) ToRawString() string {
return bytes2string(e.dst)
}
// ToHexString outputs as string with hex encoding.
func (e Encrypter) ToHexString() string {
return Encode.FromBytes(e.dst).ByHex().ToString()
}
// ToBase64String outputs as string with base64 encoding.
func (e Encrypter) ToBase64String() string {
return Encode.FromBytes(e.dst).ByBase64().ToString()
}
// ToRawBytes outputs as raw byte slice without encoding.
func (e Encrypter) ToRawBytes() []byte {
if len(e.dst) == 0 {
return []byte("")
}
return e.dst
}
// ToHexBytes outputs as byte with hex encoding.
func (e Encrypter) ToHexBytes() []byte {
return Encode.FromBytes(e.dst).ByHex().ToBytes()
}
// ToBase64Bytes outputs as byte slice with base64 encoding.
func (e Encrypter) ToBase64Bytes() []byte {
return Encode.FromBytes(e.dst).ByBase64().ToBytes()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化