public void Concat() { byte[] arg1 = { 97, 29, 31, 55, 17, 0, 129 }; byte[] arg2 = { 12, 33, 14, 40, 199, 244, 87 }; byte[] expected = { 97, 29, 31, 55, 17, 0, 129, 12, 33, 14, 40, 199, 244, 87 }; CollectionAssert.AreEqual(expected, ByteArraysUtils.Concat(arg1, arg2)); }
public byte[] EMSA_PSS_Encoding(byte[] M, int k, int sLen) { int hLen = hash.HashSize; int emLen = k / 8; var mHash = hash.ComputeHash(M); if (emLen < hLen + sLen + 2) { throw new EncodingException(); } byte[] salt = ByteArraysUtils.GetRandomOctets(RNGCryptoServiceProvider.Create(), sLen); var M_dash = ByteArraysUtils.Concat(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, ByteArraysUtils.Concat(mHash, salt)); var H = hash.ComputeHash(M_dash); var PS = new byte[emLen - sLen - hLen - 2]; var DB = ByteArraysUtils.Concat(ByteArraysUtils.Concat(PS, new byte[] { 0x01 }), salt); var dbMask = mgf.MGF1(H, emLen - hLen - 1, hash); var maskedDB = ByteArraysUtils.XorBytes(DB, dbMask); maskedDB[0] &= (byte)(0xFF >> (8 * emLen - k)); var EM = ByteArraysUtils.Concat(ByteArraysUtils.Concat(maskedDB, H), new byte[] { 0xbc }); return(EM); }