This is an Elixir implementation of the IPCrypt specification for IP address encryption and obfuscation.
- ipcrypt-deterministic: Deterministic encryption using AES-128
- ipcrypt-pfx: Prefix-preserving encryption using dual AES-128
- ipcrypt-nd: Non-deterministic encryption using KIASU-BC with 8-byte tweaks
- ipcrypt-ndx: Non-deterministic encryption using AES-XTS with 16-byte tweaks
Add ipcrypt to your list of dependencies in mix.exs:
def deps do
[
{:ipcrypt, "~> 0.2.0"}
]
end# Deterministic encryption
key16 = <<1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16>>
ip = "192.0.2.1"
encrypted_ip = IPCrypt.Deterministic.encrypt(ip, key16)
decrypted_ip = IPCrypt.Deterministic.decrypt(encrypted_ip, key16)
# Prefix-preserving encryption
key32 = <<1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32>>
encrypted_ip_pfx = IPCrypt.Pfx.encrypt(ip, key32)
decrypted_ip_pfx = IPCrypt.Pfx.decrypt(encrypted_ip_pfx, key32)
# Non-deterministic encryption with KIASU-BC
encrypted_data_nd = IPCrypt.Nd.encrypt(ip, key16)
decrypted_ip_nd = IPCrypt.Nd.decrypt(encrypted_data_nd, key16)
# Non-deterministic encryption with AES-XTS
encrypted_data_ndx = IPCrypt.Ndx.encrypt(ip, key32)
decrypted_ip_ndx = IPCrypt.Ndx.decrypt(encrypted_data_ndx, key32)You can also use the main module for a unified interface:
# Using the main IPCrypt module
encrypted_ip = IPCrypt.encrypt(ip, key32, :pfx)
decrypted_ip = IPCrypt.decrypt(encrypted_ip, key32, :pfx)To run the tests:
mix testThe tests verify the implementation against the official test vectors from the IPCrypt specification.
This implementation is released under the MIT license.