From 1aaabc7e900e79b3c0991f5048d8101c6b005563 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 22 Jul 2020 15:47:01 +0800 Subject: [PATCH] Used IStringEncryptionService to encrypt data --- .../Volo.Abp.BlobStoring.Aws.csproj | 2 -- .../Aws/AbpBlobStoringAwsModule.cs | 4 +-- .../Aws/DefaultAmazonS3ClientFactory.cs | 29 ++++++++++--------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/framework/src/Volo.Abp.BlobStoring.Aws/Volo.Abp.BlobStoring.Aws.csproj b/framework/src/Volo.Abp.BlobStoring.Aws/Volo.Abp.BlobStoring.Aws.csproj index 814158b064..d30601d1e8 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aws/Volo.Abp.BlobStoring.Aws.csproj +++ b/framework/src/Volo.Abp.BlobStoring.Aws/Volo.Abp.BlobStoring.Aws.csproj @@ -19,8 +19,6 @@ - - diff --git a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AbpBlobStoringAwsModule.cs b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AbpBlobStoringAwsModule.cs index 6f2e5dc330..28426321c8 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AbpBlobStoringAwsModule.cs +++ b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AbpBlobStoringAwsModule.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.Caching; +using Volo.Abp.Caching; using Volo.Abp.Modularity; namespace Volo.Abp.BlobStoring.Aws @@ -10,7 +9,6 @@ namespace Volo.Abp.BlobStoring.Aws { public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddDataProtection(); } } } diff --git a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/DefaultAmazonS3ClientFactory.cs b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/DefaultAmazonS3ClientFactory.cs index 717ef2e05d..78ef55aebb 100644 --- a/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/DefaultAmazonS3ClientFactory.cs +++ b/framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/DefaultAmazonS3ClientFactory.cs @@ -6,10 +6,10 @@ using Amazon.Runtime.CredentialManagement; using Amazon.S3; using Amazon.SecurityToken; using Amazon.SecurityToken.Model; -using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.Caching.Distributed; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; +using Volo.Abp.Security.Encryption; namespace Volo.Abp.BlobStoring.Aws { @@ -17,13 +17,14 @@ namespace Volo.Abp.BlobStoring.Aws { protected IDistributedCache Cache { get; } - protected IDataProtector DataProtector { get; } + protected IStringEncryptionService StringEncryptionService { get; } - public DefaultAmazonS3ClientFactory(IDistributedCache cache, - IDataProtectionProvider dataProtectionProvider) + public DefaultAmazonS3ClientFactory( + IDistributedCache cache, + IStringEncryptionService stringEncryptionService) { Cache = cache; - DataProtector = dataProtectionProvider.CreateProtector(nameof(AwsTemporaryCredentialsCacheItem)); + StringEncryptionService = stringEncryptionService; } public virtual async Task GetAmazonS3Client( @@ -114,9 +115,9 @@ namespace Volo.Abp.BlobStoring.Aws } var sessionCredentials = new SessionAWSCredentials( - DataProtector.Unprotect(temporaryCredentialsCache.AccessKeyId), - DataProtector.Unprotect(temporaryCredentialsCache.SecretAccessKey), - DataProtector.Unprotect(temporaryCredentialsCache.SessionToken)); + StringEncryptionService.Decrypt(temporaryCredentialsCache.AccessKeyId), + StringEncryptionService.Decrypt(temporaryCredentialsCache.SecretAccessKey), + StringEncryptionService.Decrypt(temporaryCredentialsCache.SessionToken)); return sessionCredentials; } @@ -165,9 +166,9 @@ namespace Volo.Abp.BlobStoring.Aws } var sessionCredentials = new SessionAWSCredentials( - DataProtector.Unprotect(temporaryCredentialsCache.AccessKeyId), - DataProtector.Unprotect(temporaryCredentialsCache.SecretAccessKey), - DataProtector.Unprotect(temporaryCredentialsCache.SessionToken)); + StringEncryptionService.Decrypt(temporaryCredentialsCache.AccessKeyId), + StringEncryptionService.Decrypt(temporaryCredentialsCache.SecretAccessKey), + StringEncryptionService.Decrypt(temporaryCredentialsCache.SessionToken)); return sessionCredentials; } @@ -176,9 +177,9 @@ namespace Volo.Abp.BlobStoring.Aws Credentials credentials) { var temporaryCredentialsCache = new AwsTemporaryCredentialsCacheItem( - DataProtector.Protect(credentials.AccessKeyId), - DataProtector.Protect(credentials.SecretAccessKey), - DataProtector.Protect(credentials.SessionToken)); + StringEncryptionService.Encrypt(credentials.AccessKeyId), + StringEncryptionService.Encrypt(credentials.SecretAccessKey), + StringEncryptionService.Encrypt(credentials.SessionToken)); await Cache.SetAsync(configuration.TemporaryCredentialsCacheKey, temporaryCredentialsCache, new DistributedCacheEntryOptions