question

SaeedPooladzadeh-4680 avatar image
0 Votes"
SaeedPooladzadeh-4680 asked BrandoZhang-MSFT commented

How can I encrypt the state file in this code?

Hello,

How can I encrypt the state file in this code:

 @code{
    
 public static IInstaApi _instaApi;
    
 public static string username { get; set; }
 public static string password { get; set; }
    
 public static string message = string.Empty;
    
 public static string ExceptionMessage = string.Empty;
    
    
    
 private static async Task StartInstagram()
 {
     var userSession = new UserSessionData
     {
         UserName = Enterance.username,
         Password = Enterance.password
     };
    
     var _instaApi = InstaApiBuilder.CreateBuilder()
 .SetUser(userSession)
 .UseLogger(new DebugLogger(LogLevel.Exceptions))
 .Build();
    
    
     const string stateFile = "state.bin";
     try
     {
         // load session file if exists
         if (File.Exists(stateFile))
         {
             //Console.WriteLine("message = "";");
             message = "Loading state from file";
    
             using (var fs = File.OpenRead(stateFile))
             {
    
    
                 _instaApi.LoadStateDataFromStream(fs);
    
             }
         }
     }
    
     catch (Exception e)
     {
         ExceptionMessage = $" error: {e}";
     }
     if (!_instaApi.IsUserAuthenticated)
     {
         // login
    
    
         message = $"Logging in as {userSession.UserName}";
         var logInResult = await _instaApi.LoginAsync();
         if (!logInResult.Succeeded)
         {
             //Console.WriteLine($"Unable to login: {logInResult.Info.Message}");
             message = $"Unable to login: {logInResult.Info.Message}";
             return;
         }
     }
    
     // save session in file
     var state = _instaApi.GetStateDataAsStream();
    
     using (var fileStream = File.Create(stateFile))
     {
         state.Seek(0, SeekOrigin.Begin);
         state.CopyTo(fileStream);
     }
    
 }
 }
dotnet-csharpdotnet-aspnet-core-blazordotnet-aspnet-core-mvc
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SaeedPooladzadeh-4680,

Could you please tell me what is this state bin file? Could you please tell me your blazor application is server application or client application?

0 Votes 0 ·

0 Answers