Skip to content

Instantly share code, notes, and snippets.

@suchithm
Created February 4, 2022 12:48
Show Gist options
  • Save suchithm/af0f5d9172e75a330437c028095e465e to your computer and use it in GitHub Desktop.
Save suchithm/af0f5d9172e75a330437c028095e465e to your computer and use it in GitHub Desktop.
DoEncryption
public static byte[] iv;
private void DoEncryption(string src, string dest)
{
IKey secretKey = GetKeyFromKeyStore();
Cipher cipher = Cipher.GetInstance("AES/GCM/NoPadding");
cipher.Init(Javax.Crypto.CipherMode.EncryptMode, secretKey);
iv = cipher.GetIV();
//var ivString = Base64.EncodeToString(iv, Base64Flags.NoWrap); //converted iv byte to string
var bytes = System.IO.File.ReadAllBytes(src);
var encryption = cipher.DoFinal(bytes);
System.IO.File.WriteAllBytes(dest, encryption);
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