1

C# で記述された次のキー生成メソッドを、Ruby に相当するものに書き直そうとしています。

        private static byte[] CreateKey(string password, int length)
        {
            var salt = new byte[] { 0x01, 0x02, 0x23, 0x34, 0x37, 0x48, 0x24, 0x63, 0x99, 0x04 };

            const int Iterations = 1000;
            using (var rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, salt, Iterations))
                return rfc2898DeriveBytes.GetBytes(length);
        }

私はPBKDF2実装を使用しています。そして、ここに私のRubyコードがあります:

def create_key password, length
    salt_a = [0x01, 0x02, 0x23, 0x34, 0x37, 0x48, 0x24, 0x63, 0x99, 0x04]
    salt = salt_a.pack('C*') # Think here there is something to change
    iterations = 1000
    derived_b = PBKDF2.new do |p| 
      p.password = password
      p.salt = salt
      p.iterations = iterations
      p.key_length = length
      p.hash_function = OpenSSL::Digest::SHA1
    end
    derived_b.bin_string # and here too
end

これら 2 つのメソッドが機能するためには、同じ出力が返される必要があります。問題は、これを行う方法がわからないことです。PBKDF2 実装はソルトを文字列として受け取りますが、C# はバイト配列を受け取ります... 問題はそこにあると思います。

4

1 に答える 1