예제 #1
0
// RFC3414 A.3
func TestPasswordToKey(t *testing.T) {
	password := "******"
	engineId := []byte{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
	}

	expBuf := []byte{
		0x52, 0x6f, 0x5e, 0xed, 0x9f, 0xcc, 0xe2, 0x6f,
		0x89, 0x64, 0xc2, 0x93, 0x07, 0x87, 0xd8, 0x2b,
	}
	key := snmpclient2.PasswordToKey(snmpclient2.Md5, password, engineId)
	if !bytes.Equal(expBuf, key) {
		t.Errorf("PasswordToKey(Md5) - expected [%s], actual [%s]",
			snmpclient2.ToHexStr(expBuf, " "), snmpclient2.ToHexStr(key, " "))
	}

	expBuf = []byte{
		0x66, 0x95, 0xfe, 0xbc, 0x92, 0x88, 0xe3, 0x62, 0x82, 0x23,
		0x5f, 0xc7, 0x15, 0x1f, 0x12, 0x84, 0x97, 0xb3, 0x8f, 0x3f,
	}
	key = snmpclient2.PasswordToKey(snmpclient2.Sha, password, engineId)
	if !bytes.Equal(expBuf, key) {
		t.Errorf("PasswordToKey(Aes) - expected [%s], actual [%s]",
			snmpclient2.ToHexStr(expBuf, " "), snmpclient2.ToHexStr(key, " "))
	}
}
예제 #2
0
func TestCipher(t *testing.T) {
	original := []byte("my private message.")
	password := "******"
	engineId := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
	engineBoots := int32(100)
	engineTime := int32(1234567)

	key := snmpclient2.PasswordToKey(snmpclient2.Sha, password, engineId)

	cipher, priv, err := snmpclient2.EncryptDES(original, key, engineBoots, 100)
	if err != nil {
		t.Errorf("DES Encrypt err %v", err)
	}
	result, err := snmpclient2.DecryptDES(cipher, key, priv)
	if err != nil {
		t.Errorf("DES Decrypt err %v", err)
	}
	if bytes.Equal(original, result) {
		t.Errorf("DES Encrypt, Decrypt - expected [%s], actual [%s]", original, result)
	}

	cipher, priv, err = snmpclient2.EncryptAES(original, key, engineBoots, engineTime, 100)
	if err != nil {
		t.Errorf("AES Encrypt err %v", err)
	}
	result, err = snmpclient2.DecryptAES(cipher, key, priv, engineBoots, engineTime)
	if err != nil {
		t.Errorf("AES Decrypt err %v", err)
	}
	if bytes.Equal(original, result) {
		t.Errorf("AES Encrypt, Decrypt - expected [%s], actual [%s]", original, result)
	}
}