.NET Secure Memory Structures

后端 未结 6 962
面向向阳花
面向向阳花 2020-12-05 16:52

I know the .NET library offers a way of storing a string in a protected/secure manner = SecureString.

My question is, if I would like to store a byte array, what wou

6条回答
  •  不知归路
    2020-12-05 16:55

    You could use SecureString to store the byte array.

      SecureString testString = new SecureString();
    
      // Assign the character array to the secure string.
      foreach (byte b in bytes)
         testString.AppendChar((char)b);
    

    then you just reverse the process to get the bytes back out.


    This isn't the only way, you can always use a MemoryBuffer and and something out of System.Security.Cryptography. But this is the only thing specifically designed to be secure in this way. All others you would have to create with the System.Security.Cryptography, which is probably the best way for you to go.

提交回复
热议问题