Devin Martin avatar Devin Martin committed dc27120

Convert the AuthData to use a protected key

Comments (0)

Files changed (2)

         const string sizeParameter = "size";
         const string counterParameter = "counter";
 
-        public byte[] Key { get; set; }
+        public Key Key { get; set; }
         public OtpType Type { get; set; }
 
         public int Step { get; set; }
 
             var otpData = new OtpAuthData();
 
-            otpData.Key = Base32.Decode(parameters[keyParameter]);
+            otpData.Key = ProtectedKey.CreateProtectedKeyAndDestroyPlaintextKey(Base32.Decode(parameters[keyParameter]));
+
             if (parameters[typeParameter] != null)
                 otpData.Type = (OtpType)Enum.Parse(typeof(OtpType), parameters[typeParameter]);
 
             get
             {
                 NameValueCollection collection = new NameValueCollection();
-                collection.Add(keyParameter, Base32.Encode(this.Key).Replace("=", "%3d"));
+                string base32Key = null;
+                this.Key.UsePlainKey(key =>
+                {
+                    base32Key = Base32.Encode(key).Replace("=", "%3d");
+                });
+                collection.Add(keyParameter, base32Key);
 
                 if (this.Type != KeeOtp.OtpType.Totp)
                     collection.Add(typeParameter, this.Type.ToString());

OtpInformation.cs

         {
             if (this.Data != null)
             {
-                this.textBoxKey.Text = Base32.Encode(this.Data.Key);
+                this.Data.Key.UsePlainKey(key =>this.textBoxKey.Text = Base32.Encode(key));
                 this.textBoxStep.Text = this.Data.Step.ToString();
 
                 if (this.Data.Size == 8)
                     return;
                 }
 
-                var key = Base32.Decode(this.textBoxKey.Text);
-
+                var key = ProtectedKey.CreateProtectedKeyAndDestroyPlaintextKey(Base32.Decode(this.textBoxKey.Text));
                 this.Data = new OtpAuthData()
                 {
                     Key = key,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.