lib/ip_anonymizer.rb in ip_anonymizer-0.2.0 vs lib/ip_anonymizer.rb in ip_anonymizer-0.3.0
- old
+ new
@@ -1,13 +1,13 @@
# stdlib
require "ipaddr"
require "openssl"
# modules
-require "ip_anonymizer/hash_ip"
-require "ip_anonymizer/mask_ip"
-require "ip_anonymizer/version"
+require_relative "ip_anonymizer/hash_ip"
+require_relative "ip_anonymizer/mask_ip"
+require_relative "ip_anonymizer/version"
module IpAnonymizer
def self.mask_ip(ip)
addr = IPAddr.new(ip.to_s)
if addr.ipv4?
@@ -22,9 +22,9 @@
def self.hash_ip(ip, key:, iterations: 1)
addr = IPAddr.new(ip.to_s)
key_len = addr.ipv4? ? 4 : 16
family = addr.ipv4? ? Socket::AF_INET : Socket::AF_INET6
- keyed_hash = OpenSSL::PKCS5.pbkdf2_hmac(addr.to_s, key, iterations, key_len, "sha256")
- IPAddr.new(keyed_hash.bytes.inject {|a, b| (a << 8) + b }, family).to_s
+ keyed_hash = OpenSSL::KDF.pbkdf2_hmac(addr.to_s, salt: key, iterations: iterations, length: key_len, hash: "sha256")
+ IPAddr.new(keyed_hash.bytes.inject { |a, b| (a << 8) + b }, family).to_s
end
end