Created
February 4, 2022 12:48
-
-
Save suchithm/af0f5d9172e75a330437c028095e465e to your computer and use it in GitHub Desktop.
DoEncryption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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