Exemple #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 := snmpgo.PasswordToKey(snmpgo.Md5, password, engineId)
	if !bytes.Equal(expBuf, key) {
		t.Errorf("passwordToKey(Md5) - expected [%s], actual [%s]",
			snmpgo.ToHexStr(expBuf, " "), snmpgo.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 = snmpgo.PasswordToKey(snmpgo.Sha, password, engineId)
	if !bytes.Equal(expBuf, key) {
		t.Errorf("passwordToKey(Aes) - expected [%s], actual [%s]",
			snmpgo.ToHexStr(expBuf, " "), snmpgo.ToHexStr(key, " "))
	}
}
Exemple #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 := snmpgo.PasswordToKey(snmpgo.Sha, password, engineId)

	cipher, priv, err := snmpgo.EncryptDES(original, key, engineBoots, 100)
	if err != nil {
		t.Errorf("DES Encrypt err %v", err)
	}
	result, err := snmpgo.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 = snmpgo.EncryptAES(original, key, engineBoots, engineTime, 100)
	if err != nil {
		t.Errorf("AES Encrypt err %v", err)
	}
	result, err = snmpgo.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)
	}
}