Skip to content

Commit

Permalink
gengx
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Jan 18, 2025
1 parent aa88bde commit 8b83cce
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions jceks/cipher_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

var (
oidPbeWithMD5And3DES = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 42, 2, 19, 1}
oidPbeWithSHA1And3DES = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 12, 1, 3}
oidPbeWithMD5And3DES = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 42, 2, 19, 1}
oidPbeWithSHA1And3DES = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 12, 1, 3}
)

var (
Expand Down
24 changes: 12 additions & 12 deletions pkcs1/cipher_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var CipherDESCBC = CipherCBC{
blockSize: des.BlockSize,
name: "DES-CBC",
}
var Cipher3DESCBC = CipherCBC{
var CipherDESEDE3CBC = CipherCBC{
cipherFunc: des.NewTripleDESCipher,
derivedKeyFunc: DeriveKey,
saltSize: 8,
Expand Down Expand Up @@ -76,8 +76,8 @@ func init() {
AddCipher(CipherDESCBC.Name(), func() Cipher {
return CipherDESCBC
})
AddCipher(Cipher3DESCBC.Name(), func() Cipher {
return Cipher3DESCBC
AddCipher(CipherDESEDE3CBC.Name(), func() Cipher {
return CipherDESEDE3CBC
})

AddCipher(CipherAES128CBC.Name(), func() Cipher {
Expand Down Expand Up @@ -110,7 +110,7 @@ var CipherDESCFB = CipherCFB{
blockSize: des.BlockSize,
name: "DES-CFB",
}
var Cipher3DESCFB = CipherCFB{
var CipherDESEDE3CFB = CipherCFB{
cipherFunc: des.NewTripleDESCipher,
derivedKeyFunc: DeriveKey,
saltSize: 8,
Expand Down Expand Up @@ -169,8 +169,8 @@ func init() {
AddCipher(CipherDESCFB.Name(), func() Cipher {
return CipherDESCFB
})
AddCipher(Cipher3DESCFB.Name(), func() Cipher {
return Cipher3DESCFB
AddCipher(CipherDESEDE3CFB.Name(), func() Cipher {
return CipherDESEDE3CFB
})

AddCipher(CipherAES128CFB.Name(), func() Cipher {
Expand Down Expand Up @@ -203,7 +203,7 @@ var CipherDESOFB = CipherOFB{
blockSize: des.BlockSize,
name: "DES-OFB",
}
var Cipher3DESOFB = CipherOFB{
var CipherDESEDE3OFB = CipherOFB{
cipherFunc: des.NewTripleDESCipher,
derivedKeyFunc: DeriveKey,
saltSize: 8,
Expand Down Expand Up @@ -262,8 +262,8 @@ func init() {
AddCipher(CipherDESOFB.Name(), func() Cipher {
return CipherDESOFB
})
AddCipher(Cipher3DESOFB.Name(), func() Cipher {
return Cipher3DESOFB
AddCipher(CipherDESEDE3OFB.Name(), func() Cipher {
return CipherDESEDE3OFB
})

AddCipher(CipherAES128OFB.Name(), func() Cipher {
Expand Down Expand Up @@ -296,7 +296,7 @@ var CipherDESCTR = CipherCTR{
blockSize: des.BlockSize,
name: "DES-CTR",
}
var Cipher3DESCTR = CipherCTR{
var CipherDESEDE3CTR = CipherCTR{
cipherFunc: des.NewTripleDESCipher,
derivedKeyFunc: DeriveKey,
saltSize: 8,
Expand Down Expand Up @@ -355,8 +355,8 @@ func init() {
AddCipher(CipherDESCTR.Name(), func() Cipher {
return CipherDESCTR
})
AddCipher(Cipher3DESCTR.Name(), func() Cipher {
return Cipher3DESCTR
AddCipher(CipherDESEDE3CTR.Name(), func() Cipher {
return CipherDESEDE3CTR
})

AddCipher(CipherAES128CTR.Name(), func() Cipher {
Expand Down
8 changes: 4 additions & 4 deletions pkcs1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ package pkcs1
// Cipher 列表
var pemCiphers = map[string]Cipher{
"DESCBC": CipherDESCBC,
"DESEDE3CBC": Cipher3DESCBC,
"DESEDE3CBC": CipherDESEDE3CBC,
"AES128CBC": CipherAES128CBC,
"AES192CBC": CipherAES192CBC,
"AES256CBC": CipherAES256CBC,
"SM4CBC": CipherSM4CBC,
"GrasshopperCBC": CipherGrasshopperCBC,

"DESCFB": CipherDESCFB,
"DESEDE3CFB": Cipher3DESCFB,
"DESEDE3CFB": CipherDESEDE3CFB,
"AES128CFB": CipherAES128CFB,
"AES192CFB": CipherAES192CFB,
"AES256CFB": CipherAES256CFB,
"SM4CFB": CipherSM4CFB,
"GrasshopperCFB": CipherGrasshopperCFB,

"DESOFB": CipherDESOFB,
"DESEDE3OFB": Cipher3DESOFB,
"DESEDE3OFB": CipherDESEDE3OFB,
"AES128OFB": CipherAES128OFB,
"AES192OFB": CipherAES192OFB,
"AES256OFB": CipherAES256OFB,
"SM4OFB": CipherSM4OFB,
"GrasshopperOFB": CipherGrasshopperOFB,

"DESCTR": CipherDESCTR,
"DESEDE3CTR": Cipher3DESCTR,
"DESEDE3CTR": CipherDESEDE3CTR,
"AES128CTR": CipherAES128CTR,
"AES192CTR": CipherAES192CTR,
"AES256CTR": CipherAES256CTR,
Expand Down
28 changes: 14 additions & 14 deletions pkcs1/pkcs1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ glcRgT6QCEtz2wIhANSyqaFtosIkHKqrDUGfz/bb5tqMYTAnBruVPaf/WEOBAiEA
9xORWeRG1tRpso4+dYy4KdDkuLPIO01KY6neYGm3BCM=`,
},
{
kind: Cipher3DESCBC,
kind: CipherDESEDE3CBC,
password: []byte("asdf"),
pemData: []byte(testingKey(`
-----BEGIN RSA TESTING KEY-----
Expand Down Expand Up @@ -357,7 +357,7 @@ q3/+myMrI9ODCgqWMbxi2/IRUEgOK1mCbWpR/UH+WZC0e8E2PZ6L0w==
-----END RSA PRIVATE KEY-----
`

var testKey_3DES_CFB = `
var testKey_DESEDE3_CFB = `
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CFB,D2C6635FFF7A4DE8
Expand All @@ -377,7 +377,7 @@ o15yE9naANp/ml1ZmFybky8cGpTYA7WTiu16PuApj9sMpfZLJjITBvvkAqccYiBt
mcOQ5xdAyTvovTQR4mxbe/SwsBtseICI7OnS4nHRcdEWcg==
-----END RSA PRIVATE KEY-----
`
var testKey_3DES_OFB = `
var testKey_DESEDE3_OFB = `
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-OFB,A0D9A77A7948C56E
Expand All @@ -397,7 +397,7 @@ awEw/CQpPQ7E2rF0YmWVOXZkWcnRXcY6TBcTjKvZqsjcvJAIOFw0NQy6V69Mgu53
nMXfIRLAvuBgtv2zcwdbgsvhAHOeV1d7l1EuISNRkBRx
-----END RSA PRIVATE KEY-----
`
var testKey_3DES_CTR = `
var testKey_DESEDE3_CTR = `
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CTR,140F4C905495A783
Expand All @@ -417,7 +417,7 @@ mSHYIoYDhxtZTPdfVo7JywEtujkgeFPG/6vpomarWRy8dAcUnLUct3BZb8lD55et
OmYAMAJyodew+6ZbTG3LRiyIH66NYGCU2Yhspd4ZeCc=
-----END RSA PRIVATE KEY-----
`
var testKey_3DES_CBC = `
var testKey_DESEDE3_CBC = `
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,9AD0BC30D5D31806
Expand Down Expand Up @@ -883,17 +883,17 @@ func Test_Check_PEMBlock(t *testing.T) {
testKeyEncryptPEMBlock(t, testKey_DES_CBC)
})

t.Run("3DES_CFB", func(t *testing.T) {
testKeyEncryptPEMBlock(t, testKey_3DES_CFB)
t.Run("DESEDE3_CFB", func(t *testing.T) {
testKeyEncryptPEMBlock(t, testKey_DESEDE3_CFB)
})
t.Run("3DES_OFB", func(t *testing.T) {
testKeyEncryptPEMBlock(t, testKey_3DES_OFB)
testKeyEncryptPEMBlock(t, testKey_DESEDE3_OFB)
})
t.Run("3DES_CTR", func(t *testing.T) {
testKeyEncryptPEMBlock(t, testKey_3DES_CTR)
t.Run("DESEDE3_CTR", func(t *testing.T) {
testKeyEncryptPEMBlock(t, testKey_DESEDE3_CTR)
})
t.Run("3DES_CBC", func(t *testing.T) {
testKeyEncryptPEMBlock(t, testKey_3DES_CBC)
t.Run("DESEDE3_CBC", func(t *testing.T) {
testKeyEncryptPEMBlock(t, testKey_DESEDE3_CBC)
})

t.Run("AES_256_CTR", func(t *testing.T) {
Expand Down Expand Up @@ -965,7 +965,7 @@ func TestEncryptPEMBlock(t *testing.T) {
t.Fatal("PEM data decrypted error: " + err.Error())
}

enblock, err := EncryptPEMBlock(rand.Reader, "RSA PRIVATE KEY", bys, []byte("123"), Cipher3DESCBC)
enblock, err := EncryptPEMBlock(rand.Reader, "RSA PRIVATE KEY", bys, []byte("123"), CipherDESEDE3CBC)
if err != nil {
t.Error("encrypt: ", err)
}
Expand Down Expand Up @@ -1011,7 +1011,7 @@ func Test_EncryptMake(t *testing.T) {
func test_EncryptMake(t *testing.T, cip Cipher) {
password := []byte("123")

block1, _ := pem.Decode([]byte(testKey_3DES_CFB))
block1, _ := pem.Decode([]byte(testKey_DESEDE3_CFB))

bys, err := DecryptPEMBlock(block1, password)
if err != nil {
Expand Down

0 comments on commit 8b83cce

Please sign in to comment.