コード例 #1
0
        /// <summary>
        /// Constructs the BlobHasher for calculating BLOB hashes.
        /// </summary>
        /// <param name="algorithm">The algorithm to use to calculate the blob hasher</param>
        /// <param name="blockSize">The block size to use in bytes</param>
        ///
        /// <exception cref="ArgumentException">
        /// If <paramref name="algorithm"/> is not a supported blob hash algorithm.
        /// </exception>
        ///
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="blockSize"/> is not a positive value.
        /// </exception>
        ///
        /// <exception cref="CryptographicUnexpectedOperationException">
        /// If the hash algorithm's hash size has a partial byte length.
        /// </exception>
        ///
        internal BlobHasher(BlobHashAlgorithm algorithm, int blockSize)
        {
            switch (algorithm)
            {
            case BlobHashAlgorithm.SHA256Block:
                _baseHashAlgorithm = SHA256.Create();
                break;

            default:
                throw new ArgumentException(
                          Resources.BlobHashAlgorithmUnsupported.FormatResource(algorithm),
                          nameof(algorithm));
            }

            if (blockSize < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(blockSize), Resources.BlockSizeMustBePositive);
            }

            if (_baseHashAlgorithm.HashSize % 8 != 0)
            {
                throw new CryptographicUnexpectedOperationException(Resources.AlgorithmHashSizePartialByteLength.FormatResource(_baseHashAlgorithm.HashSize));
            }

            BlockSize         = blockSize;
            BlobHashAlgorithm = algorithm;
            HashSizeBytes     = _baseHashAlgorithm.HashSize / 8;
        }
コード例 #2
0
 /// <summary>
 /// Creates an instance of the <see cref="BlobHashInfo"/> class
 /// for a given hashing algorithm, hashblock size and hash.
 /// </summary>
 ///
 /// <param name="blobHashAlgorithm">
 /// The hashing algorithm used.
 /// </param>
 ///
 /// <param name="blobBlockSizeBytes">
 /// The size of the BLOB block size used in calculating hashes
 /// </param>
 ///
 /// <param name="hash">
 /// Represents the BLOB hash value
 /// </param>
 public BlobHashInfo(BlobHashAlgorithm blobHashAlgorithm, int blobBlockSizeBytes, byte[] hash)
 {
     BlobHashAlgorithm        = blobHashAlgorithm;
     _blobHashAlgorithmString = blobHashAlgorithm.ToString();
     BlockSizeBytes           = blobBlockSizeBytes;
     Hash = hash;
 }
コード例 #3
0
 /// <summary>        
 /// Creates an instance of the <see cref="BlobHashInfo"/> class 
 /// for a given hashing algorithm, hashblock size and hash.
 /// <param name="blobHashAlgorithm">
 /// The hashing algorithm used.
 /// </param>
 /// 
 /// <param name="blobBlockSizeBytes">
 /// The size of the BLOB block size used in calculating hashes
 /// </param>
 ///
 /// <param name="hash">
 /// Represents the BLOB hash value 
 /// </param>
 /// 
 /// </summary>        
 public BlobHashInfo(BlobHashAlgorithm blobHashAlgorithm, Int32 blobBlockSizeBytes, byte[] hash)
 {
     _blobHashAlgorithm = blobHashAlgorithm;
     _blobHashAlgorithmString = blobHashAlgorithm.ToString();
     _blockSizeBytes = blobBlockSizeBytes;
     _hash = hash;
 }
コード例 #4
0
        /// <summary>
        /// Constructs the BlobHasher for calculating BLOB hashes.
        /// </summary>
        /// <param name="algorithm"></param>
        /// <param name="blockSize"></param>
        /// 
        /// <exception cref="ArgumentException">
        /// If <paramref name="algorithm"/> is not a supported blob hash algorithm.
        /// </exception>
        /// 
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="blockSize"/> is not a positive value. 
        /// </exception>
        /// 
        /// <exception cref="CryptographicUnexpectedOperationException">
        /// If the hash algorithm's hash size has a partial byte length.
        /// </exception>
        ///         
        internal BlobHasher(BlobHashAlgorithm algorithm, int blockSize)
        {
            switch (algorithm)
            {
                case BlobHashAlgorithm.SHA256Block:
                    _baseHashAlgorithm = CryptoConfiguration.CreateHashAlgorithm("SHA256");
                    break;
                default:
                    throw new ArgumentException(
                        ResourceRetriever.FormatResourceString(
                            "BlobHashAlgorithmUnsupported",
                             algorithm),
                        "algorithm");
            }

            Validator.ThrowArgumentOutOfRangeIf(blockSize < 1, "blockSize", "BlockSizeMustBePositive");

            if ((_baseHashAlgorithm.HashSize % 8) != 0)
            {
                throw new CryptographicUnexpectedOperationException(
                    ResourceRetriever.FormatResourceString(
                        "AlgorithmHashSizePartialByteLength",
                        _baseHashAlgorithm.HashSize));
            }

            _blockSize = blockSize;
            _blobHashAlgorithm = algorithm;
            _hashSizeBytes = _baseHashAlgorithm.HashSize / 8;
        }
コード例 #5
0
 /// <summary>
 /// Constructs a BlobPutParameters instance with the specified parameters.
 /// </summary>
 ///
 /// <param name="blobReferenceUrl">
 /// The BLOB reference URL.
 /// </param>
 ///
 /// <param name="chunkSize">
 /// The chunk size, in bytes, of the portion of a BLOB that should be sent to HealthVault
 /// in each request.
 /// </param>
 ///
 /// <param name="maxBlobSize">
 /// The maximum overall size of a BLOB in bytes.
 /// </param>
 ///
 /// <param name="blobHashAlgorithm">
 /// The hash algorithm to use for calculating the hash of this BLOB.
 /// </param>
 ///
 /// <param name="blockSize">
 /// The block size, in bytes, used by the BLOB hash algorithm.
 /// </param>
 internal BlobPutParameters(
     Uri blobReferenceUrl,
     int chunkSize,
     long maxBlobSize,
     BlobHashAlgorithm blobHashAlgorithm,
     int blockSize)
 {
     Url       = blobReferenceUrl;
     ChunkSize = chunkSize;
     PostEncryptionChunkSize = chunkSize;
     MaxBlobSize             = maxBlobSize;
     BlobHashAlgorithm       = blobHashAlgorithm;
     HashBlockSize           = blockSize;
 }
コード例 #6
0
 /// <summary>
 /// Constructs a BlobPutParameters instance with the specified parameters.
 /// </summary>
 /// 
 /// <param name="blobReferenceUrl">
 /// The BLOB reference URL.
 /// </param>
 /// 
 /// <param name="chunkSize">
 /// The chunk size, in bytes, of the portion of a BLOB that should be sent to HealthVault
 /// in each request.
 /// </param>
 /// 
 /// <param name="maxBlobSize">
 /// The maximum overall size of a BLOB in bytes.
 /// </param>
 /// 
 /// <param name="blobHashAlgorithm">
 /// The hash algorithm to use for calculating the hash of this BLOB.
 /// </param>
 /// 
 /// <param name="blockSize">
 /// The block size, in bytes, used by the BLOB hash algorithm.
 /// </param>
 internal BlobPutParameters(
     Uri blobReferenceUrl, 
     int chunkSize, 
     long maxBlobSize, 
     BlobHashAlgorithm blobHashAlgorithm,
     int blockSize)
 {
     _url = blobReferenceUrl;
     _chunkSize = chunkSize;
     _postEncryptionChunkSize = chunkSize;
     _maxBlobSize = maxBlobSize;
     _blobHashAlgorithm = blobHashAlgorithm;
     _hashBlockSize = blockSize;
 }
コード例 #7
0
        internal void Parse(XPathNavigator blobHashNav)
        {
            String blobHashAlgString = blobHashNav.SelectSingleNode("algorithm").Value;
            BlobHashAlgorithm blobHashAlg;
            try
            {
                blobHashAlg =
                    (BlobHashAlgorithm)Enum.Parse(
                        typeof(BlobHashAlgorithm), blobHashAlgString);
            }
            catch (ArgumentException)
            {
                blobHashAlg = BlobHashAlgorithm.Unknown;
            }
            _blobHashAlgorithmString = blobHashAlgString;

            Int32 blockSize = blobHashNav.SelectSingleNode("params/block-size").ValueAsInt;

            XPathNavigator hashNav = blobHashNav.SelectSingleNode("hash");

            Byte[] blobHash = null;
            if(hashNav != null)
            {
                String blobHashStr = blobHashNav.SelectSingleNode("hash").Value;
                blobHash = Convert.FromBase64String(blobHashStr);
            }

            _blobHashAlgorithm = blobHashAlg;
            _blockSizeBytes = blockSize;
            _hash = blobHash;
        }