//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// balnee
// krishnib
//------------------------------------------------------------------------------
namespace System.Data.SqlClient
{
using System;
using System.Data.SqlClient;
using System.Security.Cryptography;
///
/// Base class containing raw key bytes for symmetric key algorithms. Some encryption algorithms can use the key directly while others derive sub keys from this.
/// If an algorithm needs to derive more keys, have a derived class from this and use it in the corresponding encryption algorithm.
///
internal class SqlClientSymmetricKey {
///
/// The underlying key material
///
protected readonly byte[] _rootKey;
///
/// Constructor that initializes the root key.
///
/// root key
internal SqlClientSymmetricKey(byte[] rootKey) {
// Key validation
if (rootKey == null || rootKey.Length == 0) {
throw SQL.NullColumnEncryptionKeySysErr();
}
_rootKey = rootKey;
}
///
/// Empty destructor for binary back compat.
///
~SqlClientSymmetricKey() {
}
///
/// Returns a copy of the plain text key
/// This is needed for actual encryption/decryption.
///
internal virtual byte[] RootKey {
get {
return _rootKey;
}
}
///
/// Computes SHA256 value of the plain text key bytes
///
/// A string containing SHA256 hash of the root key
internal virtual string GetKeyHash() {
return SqlSecurityUtility.GetSHA256Hash(RootKey);
}
///
/// Gets the length of the root key
///
///
/// Returns the length of the root key
///
internal virtual int Length() {
return _rootKey.Length;
}
}
}