forked from deatil/lakego-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
299 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package des | ||
|
||
import ( | ||
"strconv" | ||
"crypto/des" | ||
"crypto/cipher" | ||
) | ||
|
||
// The DES block size in bytes. | ||
const BlockSize = des.BlockSize | ||
|
||
type KeySizeError int | ||
|
||
func (k KeySizeError) Error() string { | ||
return "crypto/des: invalid key size " + strconv.Itoa(int(k)) | ||
} | ||
|
||
type twoDESCipher struct { | ||
key1 []byte | ||
key2 []byte | ||
} | ||
|
||
// NewTwoDESCipher creates and returns a new cipher.Block. | ||
func NewTwoDESCipher(key []byte) (cipher.Block, error) { | ||
if len(key) != 16 { | ||
return nil, KeySizeError(len(key)) | ||
} | ||
|
||
c := new(twoDESCipher) | ||
c.key1 = key[:8] | ||
c.key2 = key[8:] | ||
|
||
return c, nil | ||
} | ||
|
||
func (c *twoDESCipher) BlockSize() int { | ||
return des.BlockSize | ||
} | ||
|
||
func (c *twoDESCipher) Encrypt(dst, src []byte) { | ||
encoded, err := desEncrypt(c.key1, src) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
encoded, err = desEncrypt(c.key2, encoded) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
copy(dst, encoded) | ||
} | ||
|
||
func (c *twoDESCipher) Decrypt(dst, src []byte) { | ||
decoded, err := desDecrypt(c.key2, src) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
decoded, err = desDecrypt(c.key1, decoded) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
copy(dst, decoded) | ||
} | ||
|
||
// Encrypt data | ||
func desEncrypt(key []byte, data []byte) ([]byte, error) { | ||
block, err := des.NewCipher(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dst := make([]byte, len(data)) | ||
block.Encrypt(dst, data) | ||
|
||
return dst, nil | ||
} | ||
|
||
// Decrypt data | ||
func desDecrypt(key []byte, data []byte) ([]byte, error) { | ||
block, err := des.NewCipher(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dst := make([]byte, len(data)) | ||
block.Decrypt(dst, data) | ||
|
||
return dst, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import ( | |
*/ | ||
type JCEKS struct { | ||
// 解析后数据 | ||
entries map[string]any | ||
entries map[string]any | ||
} | ||
|
||
// 构造函数 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.