public static void EncryptNtag(string savePath, AmiiboTag amiibo) { const string missingSavePath = "Missing save path"; const string missingAmibo = "Can't encrypt amiibo if no amiibo was given, DUH!"; if (string.IsNullOrEmpty(savePath)) { Console.WriteLine(missingSavePath); ActionOutput?.Invoke(null, new ActionOutputEventArgs(false, missingSavePath)); return; } if (amiibo == null) { Console.WriteLine(missingAmibo); ActionOutput?.Invoke(null, new ActionOutputEventArgs(false, missingAmibo)); return; } try { byte[] encryptedNtagData = amiibo.EncryptWithKeys(); File.WriteAllBytes(savePath, encryptedNtagData); } catch (Exception ex) { string errorEncrypting = $"Error while encrypting {amiibo.Amiibo?.AmiiboSetName}"; ActionOutput?.Invoke(null, new ActionOutputEventArgs(false, errorEncrypting + Environment.NewLine + Environment.NewLine + ex.Message)); Console.WriteLine(errorEncrypting); Console.WriteLine(ex.Message); } }
public static AmiiboTag LoadAndDecryptNtag(string amiiboPath) { var amiiboFileNotFound = $"{amiiboPath} not found!"; if (!File.Exists(amiiboPath)) { Console.WriteLine(amiiboFileNotFound); ActionOutput?.Invoke(null, new ActionOutputEventArgs(false, amiiboFileNotFound)); return(null); } byte[] encryptedNtagData = File.ReadAllBytes(amiiboPath); try { return(AmiiboTag.DecryptWithKeys(encryptedNtagData)); } catch (Exception ex) { string errorDecrypting = $"Error while decrypting {amiiboPath}"; ActionOutput?.Invoke(null, new ActionOutputEventArgs(false, errorDecrypting + Environment.NewLine + Environment.NewLine + ex.Message)); Console.WriteLine(errorDecrypting); Console.WriteLine(ex.Message); } return(null); }