Files
be.ems/src/modules/ne_data/udm_auth_k4_test.go
TsMask 45e226ce1a Refactor API tags in swagger.yaml to use shortened prefixes
- Updated tags from 'network_data' to 'ne_data' for consistency and brevity.
- Changed 'network_element' to 'ne' across various endpoints for improved readability.
- Adjusted related descriptions in the tags section to reflect the new naming conventions.
2025-08-21 14:30:09 +08:00

55 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package ne_data
import (
"crypto/des"
"errors"
"testing"
)
// UDM K4加密
func encrypt(origData, key []byte) ([]byte, error) {
if len(origData) < 1 || len(key) < 1 {
return nil, errors.New("wrong data or key")
}
block, err := des.NewCipher(key)
if err != nil {
return nil, err
}
bs := block.BlockSize()
if len(origData)%bs != 0 {
return nil, errors.New("wrong padding")
}
out := make([]byte, len(origData))
dst := out
for len(origData) > 0 {
block.Encrypt(dst, origData[:bs])
origData = origData[bs:]
dst = dst[bs:]
}
return out, nil
}
func TestEncrypt(t *testing.T) {
// key := []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}
// 0123456789abcdef
// ki := []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}
// 0123456789abcdef0123456789abcdef
// k4 password
key := []byte{0x12, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x34}
// 1234123412341234
// k4 crypt ki
ki := []byte{0x80, 0x5D, 0xAD, 0xC6, 0xE8, 0xA5, 0x4A, 0x0D, 0x59, 0xD6, 0x22, 0xC7, 0xA0, 0x4D, 0x08, 0xE0}
// 805DADC6E8A54A0D59D622C7A04D08E0
kis, err := encrypt(ki, key)
// 加密后的放导入导入文件里ki
t.Errorf("kis: %x\n", kis)
// 3e479135bb16f45dc874a18831b54d71
t.Errorf("err: %v\n", err)
}