Ejemplo n.º 1
0
func TestRandom(t *testing.T) {
	buffer_length := 1 << 20
	cycles := 1

	for i := 0; i < cycles; i++ {
		buffer, err := rnd.RandomBytes(buffer_length)
		if err != nil {
			t.Fatal(err)
		}
		password_bytes, err := rnd.RandomBytes(10)
		if err != nil {
			t.Fatal(err)
		}
		password := string(password_bytes)

		encrypted, err := PBAesEncrypt(buffer, password)
		if err != nil {
			t.Fatal(err)
		}
		decrypted, err := PBAesDecrypt(encrypted, password)
		if bytes.Compare(buffer, decrypted) != 0 {
			t.Error("original and decryoted messages mismatch")
		}
	}
}
Ejemplo n.º 2
0
func BenchmarkPBAes(b *testing.B) {
	buffer_length := b.N
	cycles := 10

	buffer, err := rnd.RandomBytes(buffer_length)
	if err != nil {
		b.Fatal(err)
	}

	password := "******"
	for i := 0; i < cycles; i++ {
		encrypted, err := PBAesEncrypt(buffer, password)
		if err != nil {
			b.Fatal(err)
		}
		decrypted, err := PBAesDecrypt(encrypted, password)
		if bytes.Compare(buffer, decrypted) != 0 {
			b.Error("original and decrypted messages mismatch")
		}
	}
}