public static byte[] UnscrambledPayload(this SPCMessage message, RSAParameters parameters) { ArgumentThrow.IfNull(message, $"Invalid {typeof(SPCMessage).Name} to unscramble. Message can not be null.", nameof(message)); ArgumentThrow.IfNull(parameters, $"Invalid {typeof(SPCMessage).Name} to unscramble. {typeof(RSAParameters).Name} can not be null.", nameof(parameters)); using (var rsa = RSA.Create()) using (var aes = Aes.Create()) { rsa.ImportParameters(parameters); aes.IV = message.IV; aes.Key = rsa.Decrypt(message.Key, RSAEncryptionPadding.OaepSHA1); aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.None; using (var decryptor = aes.CreateDecryptor()) using (var memoryStream = new MemoryStream()) using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Write)) { cryptoStream.Write(message.ContentPayload); return(memoryStream.ToArray()); } } }
public FPExtractor(FPProvider provider) { ArgumentThrow.IfNull(provider, "Unable to create inspector. Provider can not be null.", nameof(provider)); this.Providers = new List <FPProvider>() { provider }; }
internal static byte[] ToBuffer(IEnumerable <TLLVSlab> slabs) { ArgumentThrow.IfNull(slabs, $"Invalid slabs to serialize. Slab list can not be null.", nameof(slabs)); var memory = new MemoryStream(); foreach (var slab in slabs) { memory.Write(slab.Binary); } return(memory.ToArray()); }
public FPServer(FPProvider provider, IContentKeyLocator locator) { ArgumentThrow.IfNull(provider, "Unable to create server. Provider can not be null.", nameof(provider)); ArgumentThrow.IfNull(locator, "Unable to create server. Key locator can not be null.", nameof(locator)); this.Providers = new List <FPProvider>() { provider }; this.Locator = locator; this.LicenseDuration = 3600; }
internal static IEnumerable <TLLVSlab> FromBuffer(byte[] buffer) { ArgumentThrow.IfNull(buffer, $"Invalid buffer to parse slabs. Buffer can not be null.", nameof(buffer)); var memory = new ReadOnlyMemory <byte>(buffer); IList <TLLVSlab> slabs = new List <TLLVSlab>(); while (memory.Length > 0) { var slab = new TLLVSlab(memory); slabs.Add(slab); memory = memory.Slice((int)slab.Length); } return(slabs); }
public static byte[] UnscrambledParcel(this SKR1Payload payload, byte[] key) { ArgumentThrow.IfNull(payload, $"Invalid {typeof(SKR1Payload).Name} to unscramble. Payload can not be null.", nameof(payload)); ArgumentThrow.IfLengthNot(key, 16, "Invalid key to unscramble. Key buffer should be 16 bytes.", nameof(key)); using (var aes = Aes.Create()) { aes.IV = payload.IV; aes.Key = key; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.None; using (var decryptor = aes.CreateDecryptor()) using (var memoryStream = new MemoryStream()) using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Write)) { cryptoStream.Write(payload.Parcel); return(memoryStream.ToArray()); } } }
public static byte[] ScrambledParcel(this EncryptedCKParcel parcel, byte[] key) { ArgumentThrow.IfNull(parcel, $"Invalid {typeof(EncryptedCKParcel).Name} to scramble. Parcel can not be null.", nameof(parcel)); ArgumentThrow.IfLengthNot(key, 16, "Invalid key to scramble. Key buffer should be 16 bytes.", nameof(key)); using (var aes = Aes.Create()) { // aes.IV = null; aes.Key = key; aes.Mode = CipherMode.ECB; aes.Padding = PaddingMode.None; using (var encryptor = aes.CreateEncryptor()) using (var memoryStream = new MemoryStream()) using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)) { cryptoStream.Write(parcel.Binary); return(memoryStream.ToArray()); } } }