Esempio n. 1
0
		/// <summary>
		/// Encodes a buffer to a base64 string.
		/// </summary>
		/// <param name="buffer">Input buffer.</param>
		/// <returns>Base64-encoded output string.</returns>
		public static string EncodeToBase64String( IBuffer buffer )
		{
			if (buffer == null)
				throw new ArgumentNullException("buffer");

			return Convert.ToBase64String(buffer.ToArray());
		}
Esempio n. 2
0
		/// <summary>
		/// Signs digital content. For more information, see MACs, Hashes, and Signatures.
		/// </summary>
		/// <param name="key">Key used for signing.</param>
		/// <param name="data">Data to be signed.</param>
		/// <returns>Signed data.</returns>
		public static IBuffer Sign( CryptographicKey key, IBuffer data )
		{
			if (key.Hash != null)
			{
				var signature = key.Hash.ComputeHash(data.ToArray());
				return new WindowsRuntimeBuffer(signature);
			}

			throw new NotImplementedException();
		}
Esempio n. 3
0
        public int setDbCryptKey(String partition, String key, bool bPersistent)
        {
            Windows.Storage.Streams.IBuffer keyByte    = Encoding.UTF8.GetBytes(key).AsBuffer();
            DataProtectionProvider          protecotor = new DataProtectionProvider();
            IAsyncOperation <IBuffer>       task       = protecotor.ProtectAsync(keyByte);

            task.AsTask().Wait();
            Windows.Storage.Streams.IBuffer protectedKeyByte = task.GetResults();
            this.writeKeyToFile(partition, protectedKeyByte.ToArray());
            return(getErrorCode() == 0 ? 1 : 0);
        }
 public static async Task SaveToPicturesLibraryAsync(IBuffer bufImage, string fileName, CancellationToken cancellationToken = default(CancellationToken))
 {
     var folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("ImageVerificationExtras", CreationCollisionOption.OpenIfExists).AsTask(cancellationToken).ConfigureAwait(false);
     var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting).AsTask(cancellationToken).ConfigureAwait(false);
     using (var stream = await file.OpenStreamForWriteAsync().ConfigureAwait(false))
     {
         var data = bufImage.ToArray();
         await stream.WriteAsync(data, 0, data.Length, cancellationToken).ConfigureAwait(false);
         await stream.FlushAsync(cancellationToken).ConfigureAwait(false);
     }
 }
        public Salsa20RandomGenerator(IBuffer key)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            key = HashAlgorithmProvider
                .OpenAlgorithm(HashAlgorithmNames.Sha256)
                .HashData(key);

            var iv = new byte[]
            {
                0xE8, 0x30, 0x09, 0x4B,
                0x97, 0x20, 0x5D, 0x2A
            };

            _cipher = new Salsa20Cipher(key.ToArray(), iv);
        }
        string GetDataLabelString(IBuffer data, uint scanDataType)
        {
            string result = null;
            // Only certain data types contain encoded text.
            //   To keep this simple, we'll just decode a few of them.
            if (data == null)
            {
                result = "No data";
            }
            else
            {
                switch (BarcodeSymbologies.GetName(scanDataType))
                {
                    case "Upca":
                    case "UpcaAdd2":
                    case "UpcaAdd5":
                    case "Upce":
                    case "UpceAdd2":
                    case "UpceAdd5":
                    case "Ean8":
                    case "Ean13":
                        // The UPC, EAN8, EAN13, and 2 of 5 families encode the digits 0..9
                        // which are then sent to the app in a UTF8 string (like "01234")
                        // This is not an exhaustive list of symbologies that can be converted to a string
                    case "Qr":
                        // Need to distinguish the scan data among Numeric, Alphanumeric, Binary/Byte, and Kanji/Kana.
                        // But as current barcode scanner could not distinguish the data is in Binary/Byte format or in rest 3 formats.
                        // So to read the decoded data as string.
                        result = string.Format("{0}", System.Text.Encoding.UTF8.GetString(data.ToArray()));
                        break;
                    default:
                        // Some other unsupport symbologies and just leave it as binary data
                        result = string.Format("Decoded data unavailable. Raw label data: {0}", GetDataString(data));
                        break;
                }
            }

            return result;
        }
Esempio n. 7
0
        public async Task SetAsync(string key, IBuffer buffer, DateTime expires)
        {
            if (key == null)
            {
                throw new ArgumentNullException("The parameter key must not be null.");
            }

            if (buffer == null)
            {
                throw new ArgumentNullException("The parameter buffer must not be null.");
            }

            if (fileDb.IsOpen)
            {
                var bytes = buffer.ToArray();
                var ok = await Task.Run(() => AddOrUpdateRecord(key, bytes, expires));

                if (!ok && (await RepairDatabase()))
                {
                    await Task.Run(() => AddOrUpdateRecord(key, bytes, expires));
                }
            }
        }
 public async Task<string> CreateStringFromBuffer(IBuffer buffer)
 {
     var bytes = buffer.ToArray();
     return await Task.FromResult(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
 }
		internal async Task<WriteResponse> WriteAsyncInternal(byte handle, IBuffer data)
		{
			await brick.SendCommandAsyncInternal(RequestTelegram.Write(handle, data.ToArray()));
			return ResponseTelegram.Write(brick.LastResponse);
		}
Esempio n. 10
0
        private async void SaveImage(IBuffer pixelBuffer)
        {
            //Rendu du composant Xaml, ici le graphique 'Syncfusion.Chart', sous forme d'image en mémoire.
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
            //await renderTargetBitmap.RenderAsync(doughnutMadelin, (int)myDoughnutActualWidth, (int)myDoughnut.ActualHeight);
            // var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();

            var localFolder = Windows.Storage.KnownFolders.PicturesLibrary;
            string filepicname = homewebview.DocumentTitle;
          //  var localFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var saveFile = await localFolder.CreateFileAsync(filepicname+".png", Windows.Storage.CreationCollisionOption.OpenIfExists);

            // Encodage de l'image en mémoire dans le fichier désigné sur le disque
            using (var fileStream = await saveFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
            {
                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                encoder.SetPixelData(
                    BitmapPixelFormat.Rgba8,
                    BitmapAlphaMode.Premultiplied,
                    (uint)homewebview.ActualWidth,
                    (uint)homewebview.ActualHeight,
                    DisplayInformation.GetForCurrentView().LogicalDpi,
                    DisplayInformation.GetForCurrentView().LogicalDpi,
                    pixelBuffer.ToArray());

                await encoder.FlushAsync();
            }
            MessageDialog one = new MessageDialog("截图保存到图片库");
            await one.ShowAsync();
        }
		internal async Task MessageWriteAsyncInternal(int inboxNumber, IBuffer message)
		{
			await brick.SendCommandAsyncInternal(RequestTelegram.MessageWrite(inboxNumber, message.ToArray()));
		}
		internal async Task LowSpeedWriteAsyncInternal(SensorPort sensorPort, IBuffer data, byte responseLength)
		{
			await brick.SendCommandAsyncInternal(RequestTelegram.LowSpeedWrite(sensorPort, data.ToArray(), responseLength));
		}
Esempio n. 13
0
        private async void _colorImage_ImageOpened(object sender, RoutedEventArgs e)
        {
            if (_rtb != null) _rtb = null;
            _rtb = new RenderTargetBitmap();

            await _rtb.RenderAsync(_colorImage);
            _pixelBuffer = await _rtb.GetPixelsAsync();
            _pixelBufferData = _pixelBuffer.ToArray();
        }
Esempio n. 14
0
 public void UpdateData(Windows.Storage.Streams.IBuffer buffer)
 {
     this.data = buffer.ToArray();
     ParseData();
 }
Esempio n. 15
0
        /// <summary>
        /// Gets the database schema version.
        /// </summary>
        /// <param name="buffer">The version bytes buffer</param>
        /// <returns>The database schema version.</returns>
        private static Version GetVersion(IBuffer buffer)
        {
            if (buffer == null)
                throw new ArgumentNullException("buffer");

            var bytes = buffer.ToArray(0, 4);
            var minor = BitConverter.ToUInt16(bytes, 0);
            var major = BitConverter.ToUInt16(bytes, 2);

            return new Version(major, minor);
        }
Esempio n. 16
0
        /// <summary>
        /// Parse the headers fields.
        /// </summary>
        /// <param name="input">The input stream.</param>
        /// <param name="buffer">The header bytes reader.</param>
        /// <returns>The file headers.</returns>
        private static async Task<FileHeaders> GetHeaders(
            IInputStream input, IBuffer buffer)
        {
            var result = new FileHeaders();

            while (true)
            {
                buffer = await input.ReadAsync(buffer, 3);
                var field = (HeaderFields)buffer.GetByte(0);
                var size = BitConverter.ToUInt16(buffer.ToArray(1, 2), 0);

                if (size > 0)
                    buffer = await input.ReadAsync(buffer, size);

                switch (field)
                {
                    case HeaderFields.EndOfHeader:
                        return result;

                    case HeaderFields.CompressionFlags:
                        result.UseGZip = buffer.GetByte(0) == 1;
                        break;

                    case HeaderFields.EncryptionIV:
                        result.EncryptionIV = buffer
                            .ToArray().AsBuffer();
                        break;

                    case HeaderFields.MasterSeed:
                        result.MasterSeed = buffer
                            .ToArray().AsBuffer();
                        break;

                    case HeaderFields.StreamStartBytes:
                        result.StartBytes = buffer
                            .ToArray().AsBuffer();
                        break;

                    case HeaderFields.TransformSeed:
                        result.TransformSeed = buffer
                            .ToArray().AsBuffer();
                        break;

                    case HeaderFields.TransformRounds:
                        result.TransformRounds = BitConverter.ToUInt64(
                            buffer.ToArray(), 0);
                        break;

                    case HeaderFields.ProtectedStreamKey:
                        result.ProtectedStreamKey = buffer
                            .ToArray().AsBuffer();
                        break;

                    case HeaderFields.InnerRandomStreamID:
                        result.RandomAlgorithm = (CrsAlgorithm)
                            BitConverter.ToUInt32(buffer.ToArray(), 0);
                        break;
                }
            }
        }