public static void ParseStream(Stream stream) { AudioTags audioTags = new AudioTags(); audioTags.AudioTagParse += AudioTagParse; try { audioTags.ReadTags(stream); } catch (Exception ex) { Console.WriteLine("[-] Exception thrown: {0}", ex); return; } // For each Id3v2 tag found foreach (IAudioTagOffset tagOffset in audioTags.Where(t => t.AudioTag is Id3v2Tag)) { Id3v2Tag tag = tagOffset.AudioTag as Id3v2Tag; if (tag == null) continue; // For each frame in the Id3v2 tag foreach (Id3v2Frame frame in tag.Frames) { // Set encryption frame.UseEncryption = true; // Set the cryptor frame.Cryptor = new Id3v2FrameCryption(); } // Write the tag to a byte array into a memory stream (this will trigger encrypting each frame). MemoryStream ms = new MemoryStream(tag.ToByteArray()); // Read the tag again from the memory stream (this will trigger decrypting each frame). Id3v2TagReader tagReader = new Id3v2TagReader(); IAudioTagOffset decryptedTagOffset = tagReader.ReadFromStream(ms, tagOffset.TagOrigin); if (decryptedTagOffset != null) { Id3v2Tag decryptedTag = decryptedTagOffset.AudioTag as Id3v2Tag; if (decryptedTag != null) Console.WriteLine("[*] Frames use encryption: {0}", decryptedTag.Frames.All(f => f.UseEncryption)); } } }
public static void ParseStream(Stream stream) { AudioTags audioTags = new AudioTags(); audioTags.AudioTagParse += AudioTagParse; try { audioTags.ReadTags(stream); } catch (Exception ex) { Console.WriteLine("[-] Exception thrown: {0}", ex); return; } foreach (IAudioTagOffset tagOffset in audioTags.Where(t => t.AudioTag is Id3v2Tag)) { Id3v2Tag tag = tagOffset.AudioTag as Id3v2Tag; if (tag == null) continue; Id3v2ExperimentalTestFrame testFrame = tag.GetFrame<Id3v2ExperimentalTestFrame>(); if (testFrame == null) { testFrame = new Id3v2ExperimentalTestFrame(tag.Version) { TextEncodingType = Id3v2FrameEncodingType.UTF16BigEndian, TaggingLibraryUsed = "This one", TaggingLibraryAuthor = "Me", TaggingLibraryWebsite = "http://www.google.com/", TaggingLibrarySupportsFrame = true, DateOfTag = DateTime.MaxValue }; tag.SetFrame(testFrame); } } }