I've been looking to translate the sample Java Android Pay Processing code into C#. The sample Java code can be found here: https://developers.google.com/android-pay/integration/gateway-processor-integration
Parsing through BouncyCastle's C# documentation, I have found equivalents to most of the Java BouncyCastle code. However, I could not find HKDFBytesGenerator and HKDFParameters as part of the C# library, and the BaseKDFBytesGenerator does not produce the correct encryptionKey and macKey.
Would anyone know of the proper HKDF substitution in the BouncyCastle C# library? Or if it does not exist, how to substitute it with .NET's built in cryptography library or other .NET cryptography library?
Edit: For reference, the code I am struggling with is here:
// Deriving encryption and mac keys.
HKDFBytesGenerator hkdfBytesGenerator = new HKDFBytesGenerator(new SHA256Digest());
byte[] khdfInput = ByteUtils.concatenate(ephemeralPublicKeyBytes, sharedSecret);
hkdfBytesGenerator.init(new HKDFParameters(khdfInput, HKDF_SALT, HKDF_INFO));
byte[] encryptionKey = new byte[SYMMETRIC_KEY_BYTE_COUNT];
hkdfBytesGenerator.generateBytes(encryptionKey, 0, SYMMETRIC_KEY_BYTE_COUNT);
byte[] macKey = new byte[MAC_KEY_BYTE_COUNT];
hkdfBytesGenerator.generateBytes(macKey, 0, MAC_KEY_BYTE_COUNT);
答案 0 :(得分:0)
通过对外部库的进一步研究,我发现CEX-NET基于BouncyCastle的1.51 Java实现有一个很棒的HKDF类。该库能够处理获取正确的encryptionKey和macKey的步骤。链接:http://web.ncf.ca/fq329/CEX/Help/class_v_t_dev_1_1_libraries_1_1_c_e_x_engine_1_1_crypto_1_1_generator_1_1_h_k_d_f.html#details