Skip to content

Instantly share code, notes, and snippets.

@jedisct1
Created August 24, 2023 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedisct1/ce4fe6d670b781d00afea350578eb295 to your computer and use it in GitHub Desktop.
Save jedisct1/ce4fe6d670b781d00afea350578eb295 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/aes"
"net"
)
func EncryptIp(key []byte, ip net.IP) net.IP {
cipher, err := aes.NewCipher(key)
if err != nil {
panic(err)
}
encrypted_ip := ip.To16()
cipher.Encrypt(encrypted_ip, encrypted_ip)
return encrypted_ip
}
func main() {
key := []byte("example key 1234") // must be 16 bytes
ip := net.IPv4(93, 184, 216, 3)
encrypted_ip := EncryptIp(key, ip)
println(encrypted_ip.String())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment