コード例 #1
0
        public EncryptedMessage CreateEncryptedMessage(object request, string operationName, byte[] cryptKey, byte[] authKey, byte[] iv, string verb = null)
        {
            this.PopulateRequestMetadata(request);

            if (verb == null)
            {
                verb = HttpMethods.Post;
            }

            var cryptAuthKeys = cryptKey.Combine(authKey);

            var rsaEncCryptAuthKeys     = RsaUtils.Encrypt(cryptAuthKeys, PublicKey);
            var authRsaEncCryptAuthKeys = HmacUtils.Authenticate(rsaEncCryptAuthKeys, authKey, iv);

            var timestamp   = DateTime.UtcNow.ToUnixTime();
            var requestBody = timestamp + " " + verb + " " + operationName + " " + request.ToJson();

            var encryptedBytes     = AesUtils.Encrypt(requestBody.ToUtf8Bytes(), cryptKey, iv);
            var authEncryptedBytes = HmacUtils.Authenticate(encryptedBytes, authKey, iv);

            var encryptedMessage = new EncryptedMessage
            {
                KeyId = KeyId,
                EncryptedSymmetricKey = Convert.ToBase64String(authRsaEncCryptAuthKeys),
                EncryptedBody         = Convert.ToBase64String(authEncryptedBytes),
            };

            return(encryptedMessage);
        }
コード例 #2
0
        public EncryptedMessage CreateEncryptedMessage(object request, string operationName, SymmetricAlgorithm aes, string verb = null)
        {
            this.PopulateRequestMetadata(request);

            var aesKeyBytes = aes.Key.Combine(aes.IV);

            var rsaEncAesKeyBytes = RsaUtils.Encrypt(aesKeyBytes, PublicKey);

            if (verb == null)
            {
                verb = HttpMethods.Post;
            }

            var timestamp = DateTime.UtcNow.ToUnixTime();

            var requestBody = timestamp + " " + verb + " " + operationName + " " + JsonServiceClient.ToJson(request);

            var encryptedMessage = new EncryptedMessage
            {
                EncryptedSymmetricKey = Convert.ToBase64String(rsaEncAesKeyBytes),
                EncryptedBody         = AesUtils.Encrypt(requestBody, aes.Key, aes.IV)
            };

            return(encryptedMessage);
        }
コード例 #3
0
 public object Any(EncryptedMessage request)
 {
     throw new NotImplementedException("EncryptedMessages Service cannot be called directly");
 }