1. Devin Martin
  2. KeeOtp

Commits

Devin Martin  committed dc27120

Convert the AuthData to use a protected key

Comments (0)

Files changed (2)

File OtpAuthData.cs Modified

View file
  • Ignore whitespace
  • Hide word diff
         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());

File OtpInformation.cs Modified

View file
  • Ignore whitespace
  • Hide word diff
         {
             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,