Skip to content

Conversation

@CharithW
Copy link

@CharithW CharithW commented Jan 8, 2018

  • a task list item
  • list syntax required
  • normal formatting, @mentions, #1234 refs
  • incomplete
  • completed

{
public class Encrypt
{
readonly string PasswordHash ="SampleHash";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inject the Secrets to the class via .net DI framework. Refer the code written Decrypt.cs

{
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format the document.

byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the corresponding types instead of var.

cipherTextBytes = memoryStream.ToArray();
cryptoStream.Close();
}
memoryStream.Close();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memoryStream closes automatically once the execution has done within the using statement. Not need to specifically close.

}
}

static SymmetricAlgorithm CreateAlgorithm()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing the accessibility of the method and available as an instance method instead of static. You can change this to private SymmetricAlgorithm CreateAlgorithm() instead.
OR
reuse the same logic written on Decrypt.cs

}
memoryStream.Close();
}
string encrypted_text = Convert.ToBase64String(cipherTextBytes);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider returning the converted string instead of assigning to a local variable and returning the variable instance.

@CharithW
Copy link
Author

CharithW commented Jan 8, 2018

Noted and will add these changes

{
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the line is bit off indented? Applicable to several places.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that @kosalanuwan already pointed it out. Ignore my comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants