ServiceStack.AesUtils.CreateCryptAuthKeysAndIv C# (CSharp) Méthode

CreateCryptAuthKeysAndIv() public static méthode

public static CreateCryptAuthKeysAndIv ( byte &cryptKey, byte &authKey, byte &iv ) : void
cryptKey byte
authKey byte
iv byte
Résultat void
        public static void CreateCryptAuthKeysAndIv(out byte[] cryptKey, out byte[] authKey, out byte[] iv)
        {
            using (var aes = CreateSymmetricAlgorithm())
            {
                cryptKey = aes.Key;
                iv = aes.IV;
            }
            using (var aes = CreateSymmetricAlgorithm())
            {
                authKey = aes.Key;
            }
        }

Usage Example

        public TResponse Send <TResponse>(string httpMethod, object request)
        {
            byte[] cryptKey, authKey, iv;
            AesUtils.CreateCryptAuthKeysAndIv(out cryptKey, out authKey, out iv);

            try
            {
                var encryptedMessage = CreateEncryptedMessage(request, request.GetType().Name, cryptKey, authKey, iv, httpMethod);
                var encResponse      = Client.Send(encryptedMessage);

                var authEncryptedBytes = Convert.FromBase64String(encResponse.EncryptedBody);

                if (!HmacUtils.Verify(authEncryptedBytes, authKey))
                {
                    throw new Exception("Invalid EncryptedBody");
                }

                var decryptedBytes = HmacUtils.DecryptAuthenticated(authEncryptedBytes, cryptKey);

                var responseJson = decryptedBytes.FromUtf8Bytes();
                var response     = responseJson.FromJson <TResponse>();

                return(response);
            }
            catch (WebServiceException ex)
            {
                throw DecryptedException(ex, cryptKey, authKey);
            }
        }
All Usage Examples Of ServiceStack.AesUtils::CreateCryptAuthKeysAndIv