代码拉取完成,页面将自动刷新
同步操作将从 dromara/dongle 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package dongle
import (
"github.com/stretchr/testify/assert"
"strconv"
"testing"
)
var tripleDesCfbTest = []struct {
padding cipherPadding
input string
key string
iv string
toHex string
toBase32 string
toBase64 string
}{
{"", "", "0123456789abcdefghijklmn", "12345678", "", "", ""},
{No, "hello world, go!", "0123456789abcdefghijklmn", "12345678", "f52dc896ceff0ecc9393c19d4e1e7591", "6UW4RFWO74HMZE4TYGOU4HTVSE======", "9S3Ils7/DsyTk8GdTh51kQ=="},
{Zero, "hello world", "0123456789abcdefghijklmn", "12345678", "f52dc896ceff0ecc9393c1b16e791ab0", "6UW4RFWO74HMZE4TYGYW46I2WA======", "9S3Ils7/DsyTk8GxbnkasA=="},
{PKCS5, "hello world", "0123456789abcdefghijklmn", "12345678", "f52dc896ceff0ecc9393c1b46b7c1fb5", "6UW4RFWO74HMZE4TYG2GW7A7WU======", "9S3Ils7/DsyTk8G0a3wftQ=="},
{PKCS7, "hello world", "0123456789abcdefghijklmn", "12345678", "f52dc896ceff0ecc9393c1b46b7c1fb5", "6UW4RFWO74HMZE4TYG2GW7A7WU======", "9S3Ils7/DsyTk8G0a3wftQ=="},
}
func TestEncrypt_By3Des_CFB_ToString(t *testing.T) {
for index, test := range tripleDesCfbTest {
e := Encrypt.FromString(test.input).By3Des(tripleDesCipher(CFB, test.padding, test.key, test.iv))
assert.Nil(t, e.Error)
assert.Equal(t, test.toHex, e.ToHexString(), "Hex test index is "+strconv.Itoa(index))
assert.Equal(t, test.toBase32, e.ToBase32String(), "Base32 test index is "+strconv.Itoa(index))
assert.Equal(t, test.toBase64, e.ToBase64String(), "Base64 test index is "+strconv.Itoa(index))
}
}
func TestDecrypt_By3Des_CFB_ToString(t *testing.T) {
for index, test := range tripleDesCfbTest {
e := Decrypt.FromHexString(test.toHex).By3Des(tripleDesCipher(CFB, test.padding, test.key, test.iv))
assert.Nil(t, e.Error)
assert.Equal(t, test.input, e.ToString(), "Hex test index is "+strconv.Itoa(index))
}
for index, test := range tripleDesCfbTest {
e := Decrypt.FromBase32String(test.toBase32).By3Des(tripleDesCipher(CFB, test.padding, test.key, test.iv))
assert.Nil(t, e.Error)
assert.Equal(t, test.input, e.ToString(), "Base32 test index is "+strconv.Itoa(index))
}
for index, test := range tripleDesCfbTest {
e := Decrypt.FromBase64String(test.toBase64).By3Des(tripleDesCipher(CFB, test.padding, test.key, test.iv))
assert.Nil(t, e.Error)
assert.Equal(t, test.input, e.ToString(), "Base64 test index is "+strconv.Itoa(index))
}
}
func TestEncrypt_By3Des_CFB_ToBytes(t *testing.T) {
for index, test := range tripleDesCfbTest {
e := Encrypt.FromString(test.input).By3Des(tripleDesCipher(CFB, test.padding, []byte(test.key), []byte(test.iv)))
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.toHex), e.ToHexBytes(), "Hex test index is "+strconv.Itoa(index))
assert.Equal(t, []byte(test.toBase32), e.ToBase32Bytes(), "Base32 test index is "+strconv.Itoa(index))
assert.Equal(t, []byte(test.toBase64), e.ToBase64Bytes(), "Base64 test index is "+strconv.Itoa(index))
}
}
func TestDecrypt_By3Des_CFB_ToBytes(t *testing.T) {
for index, test := range tripleDesCfbTest {
e := Decrypt.FromHexBytes([]byte(test.toHex)).By3Des(tripleDesCipher(CFB, test.padding, []byte(test.key), []byte(test.iv)))
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.input), e.ToBytes(), "Hex test index is "+strconv.Itoa(index))
}
for index, test := range tripleDesCfbTest {
e := Decrypt.FromBase32Bytes([]byte(test.toBase32)).By3Des(tripleDesCipher(CFB, test.padding, []byte(test.key), []byte(test.iv)))
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.input), e.ToBytes(), "Base32 test index is "+strconv.Itoa(index))
}
for index, test := range tripleDesCfbTest {
e := Decrypt.FromBase64Bytes([]byte(test.toBase64)).By3Des(tripleDesCipher(CFB, test.padding, []byte(test.key), []byte(test.iv)))
assert.Nil(t, e.Error)
assert.Equal(t, []byte(test.input), e.ToBytes(), "Base64 test index is "+strconv.Itoa(index))
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。