/// <summary> /// Encrypts Message. User decides what SecBuffers are used. /// </summary> /// <param name="kileRole">Represents client or server</param> /// <param name="securityBuffers">The security buffers to encrypt.</param> /// <exception cref="System.ArgumentException">Thrown when the data or token is not valid.</exception> internal static void Encrypt(KileRole kileRole, params SecurityBuffer[] securityBuffers) { byte[] message = SspiUtility.ConcatenateReadWriteSecurityBuffers(securityBuffers, SecurityBufferType.Data); byte[] token = SspiUtility.ConcatenateSecurityBuffers(securityBuffers, SecurityBufferType.Token); if (token.Length == 0) { throw new ArgumentException("Token buffer is not valid."); } SGN_ALG sgnAlg = GetSgnAlg(kileRole); KilePdu pdu = kileRole.GssWrap(true, sgnAlg, message); byte[] cipherData = null; if (pdu.GetType() == typeof(Token4121)) { cipherData = pdu.ToBytes(); } else { byte[] allData = pdu.ToBytes(); byte[] paddingData = ((Token1964_4757)pdu).paddingData; cipherData = ArrayUtility.SubArray(allData, 0, allData.Length - paddingData.Length); SspiUtility.UpdateSecurityBuffers(securityBuffers, SecurityBufferType.Padding, paddingData); } SspiUtility.UpdateSecurityBuffers(securityBuffers, SecurityBufferType.Data, ArrayUtility.SubArray(cipherData, cipherData.Length - message.Length)); SspiUtility.UpdateSecurityBuffers(securityBuffers, SecurityBufferType.Token, ArrayUtility.SubArray(cipherData, 0, cipherData.Length - message.Length)); }
/// <summary> /// This takes the given SecurityBuffer array, signs data part, and updates signature into token part /// </summary> /// <param name="kileRole">Represents client or server</param> /// <param name="securityBuffers">Data to sign and token to update.</param> /// <exception cref="System.ArgumentException">Thrown when the data or token is not valid.</exception> internal static void Sign(KileRole kileRole, params SecurityBuffer[] securityBuffers) { byte[] token = SspiUtility.ConcatenateReadWriteSecurityBuffers(securityBuffers, SecurityBufferType.Token); if (token.Length == 0) { throw new ArgumentException("No token can be updated for signature."); } byte[] message = GetToBeSignedDataFromSecurityBuffers(securityBuffers); SGN_ALG sgnAlg = GetSgnAlg(kileRole); KilePdu pdu = kileRole.GssGetMic(sgnAlg, message); byte[] signature = pdu.ToBytes(); SspiUtility.UpdateSecurityBuffers(securityBuffers, SecurityBufferType.Token, signature); }