Beispiel #1
0
        protected virtual void Serialize(
            SecureMemoryHandle keyHandle,
            Span <byte> span)
        {
            Debug.Assert(keyHandle != null);
            Debug.Assert(keyHandle.Length == _keySize);
            Debug.Assert(span.Length == _keySize);

            keyHandle.Export(span);
        }
Beispiel #2
0
        protected override void Serialize(
            SecureMemoryHandle keyHandle,
            Span <byte> span)
        {
            Debug.Assert(keyHandle != null);
            Debug.Assert(keyHandle.Length == crypto_scalarmult_curve25519_SCALARBYTES);
            Debug.Assert(span.Length == crypto_scalarmult_curve25519_SCALARBYTES);

            keyHandle.Export(span);
        }
Beispiel #3
0
        internal override int ExportKey(
            SecureMemoryHandle keyHandle,
            KeyBlobFormat format,
            Span<byte> blob)
        {
            if (format != KeyBlobFormat.RawSymmetricKey)
                throw Error.Argument_FormatNotSupported(nameof(format), format.ToString());
            if (blob.Length < keyHandle.Length)
                throw Error.Argument_SpanBlob(nameof(blob));

            Debug.Assert(keyHandle != null);
            return keyHandle.Export(blob);
        }
Beispiel #4
0
        public bool TryExport(
            SecureMemoryHandle keyHandle,
            Span <byte> blob,
            out int blobSize)
        {
            Debug.Assert(keyHandle != null);
            Debug.Assert(keyHandle.Length >= _minKeySize);
            Debug.Assert(keyHandle.Length <= _maxKeySize);

            blobSize = keyHandle.Length;

            if (blob.Length < blobSize)
            {
                return(false);
            }

            keyHandle.Export(blob);
            return(true);
        }
Beispiel #5
0
        public bool TryExport(
            SecureMemoryHandle keyHandle,
            Span <byte> blob,
            out int blobSize)
        {
            Debug.Assert(keyHandle != null);
            Debug.Assert(keyHandle.Length >= _minKeySize);
            Debug.Assert(keyHandle.Length <= _maxKeySize);

            blobSize = _blobHeader.Length + sizeof(uint) + keyHandle.Length;

            if (blob.Length < blobSize)
            {
                return(false);
            }

            _blobHeader.CopyTo(blob);
            blob.Slice(_blobHeader.Length).WriteLittleEndian((uint)keyHandle.Length);
            keyHandle.Export(blob.Slice(_blobHeader.Length + sizeof(uint)));
            return(true);
        }