Skip to content

Instantly share code, notes, and snippets.

@suchithm
Created February 4, 2022 13:18
Show Gist options
  • Save suchithm/a8790db1ecc780086be44ef20f2a6ef7 to your computer and use it in GitHub Desktop.
Save suchithm/a8790db1ecc780086be44ef20f2a6ef7 to your computer and use it in GitHub Desktop.
DoDecryption
private void DoDecryption(string src, string dest)
{
//iv = Base64.Decode(ivString , Base64Flags.NoWrap);
if (iv != null && iv.Length > 0)
{
var secretKey = GetKeyFromKeyStore();
Cipher cipher = Cipher.GetInstance("AES/GCM/NoPadding");
Javax.Crypto.Spec.GCMParameterSpec spec = new Javax.Crypto.Spec.GCMParameterSpec(128, iv);
cipher.Init(Javax.Crypto.CipherMode.DecryptMode, secretKey, spec);
var bytes = System.IO.File.ReadAllBytes(src);
byte[] decodedData = cipher.DoFinal(bytes);
System.IO.File.WriteAllBytes(dest, decodedData);
if (System.IO.File.Exists(dest))
{
System.IO.File.Delete(src);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment