Monobjc.Foundation.NSData.GetBuffer C# (CSharp) Method

GetBuffer() public method

Gets a managed byte buffer from this instance.
public GetBuffer ( ) : byte[]
return byte[]
        public byte[] GetBuffer()
        {
            byte[] buffer = new byte[(int)this.Length];
            Marshal.Copy(this.Bytes, buffer, 0, (int)this.Length);
            return buffer;
        }

Usage Example

Example #1
0
 /// <summary>
 /// Decrypts the given data by using the <see cref="ArtworkEncrypter"/> tool.
 /// </summary>
 /// <param name="encryptedData">The encrypted artwork data.</param>
 /// <param name="encryptionSeed">The encryption seed to use.</param>
 /// <returns>The decrypted artwork data.</returns>
 public static NSData DecryptData(NSData encryptedData, NSString encryptionSeed)
 {
     NSData result;
     try
     {
         Aes aes = FileEncrypter.GetProvider(encryptionSeed);
         byte[] encryptedBytes = encryptedData.GetBuffer();
         byte[] decryptedBytes = FileEncrypter.Decrypt(encryptedBytes, aes);
         result = new NSData(decryptedBytes);
     }
     catch (Exception e)
     {
         Logger.Warn("NSData", "Cannot decrypt encrypted data: " + e);
         result = NSData.Data.Copy<NSData>();
     }
     return result.SafeAutorelease<NSData>();
 }