本文整理汇总了C#中KeePassLib.Security.ProtectedBinary类的典型用法代码示例。如果您正苦于以下问题:C# ProtectedBinary类的具体用法?C# ProtectedBinary怎么用?C# ProtectedBinary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProtectedBinary类属于KeePassLib.Security命名空间,在下文中一共展示了ProtectedBinary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: KcpCustomKey
public KcpCustomKey(byte[] pbKeyData)
{
Debug.Assert(pbKeyData != null); if(pbKeyData == null) throw new ArgumentNullException("pbKeyData");
SHA256Managed sha256 = new SHA256Managed();
byte[] pbRaw = sha256.ComputeHash(pbKeyData);
m_pbKey = new ProtectedBinary(true, pbRaw);
}
示例2: KcpKeyFile
public KcpKeyFile(string strKeyFile)
{
byte[] pbKey = LoadXmlKeyFile(strKeyFile);
if(pbKey == null) pbKey = LoadKeyFile(strKeyFile);
if(pbKey == null) throw new InvalidOperationException();
m_strPath = strKeyFile;
m_pbKeyData = new ProtectedBinary(true, pbKey);
}
示例3: SetKey
private void SetKey(byte[] pbPasswordUtf8)
{
Debug.Assert(pbPasswordUtf8 != null);
if(pbPasswordUtf8 == null) throw new ArgumentNullException("pbPasswordUtf8");
SHA256Managed sha256 = new SHA256Managed();
byte[] pbRaw = sha256.ComputeHash(pbPasswordUtf8);
m_psPassword = new ProtectedString(true, pbPasswordUtf8);
m_pbKeyData = new ProtectedBinary(true, pbRaw);
}
示例4: GetKeyParts
internal static ProtectedString GetKeyParts(byte[] pbPasswordUtf8, out ProtectedBinary pbKeyData)
{
Debug.Assert(pbPasswordUtf8 != null);
if(pbPasswordUtf8 == null) throw new ArgumentNullException("pbPasswordUtf8");
SHA256Managed sha256 = new SHA256Managed();
byte[] pbRaw = sha256.ComputeHash(pbPasswordUtf8);
var psPassword = new ProtectedString(true, pbPasswordUtf8);
pbKeyData = new ProtectedBinary(true, pbRaw);
return psPassword;
}
示例5: SetKey
private void SetKey(byte[] pbPasswordUtf8)
{
Debug.Assert(pbPasswordUtf8 != null);
if(pbPasswordUtf8 == null) throw new ArgumentNullException("pbPasswordUtf8");
#if (DEBUG && !KeePassLibSD)
Debug.Assert(ValidatePassword(pbPasswordUtf8));
#endif
byte[] pbRaw = CryptoUtil.HashSha256(pbPasswordUtf8);
m_psPassword = new ProtectedString(true, pbPasswordUtf8);
m_pbKeyData = new ProtectedBinary(true, pbRaw);
}
示例6: KcpCustomKey
public KcpCustomKey(string strName, byte[] pbKeyData, bool bPerformHash)
{
Debug.Assert(strName != null); if(strName == null) throw new ArgumentNullException("strName");
Debug.Assert(pbKeyData != null); if(pbKeyData == null) throw new ArgumentNullException("pbKeyData");
m_strName = strName;
if(bPerformHash)
{
SHA256Managed sha256 = new SHA256Managed();
byte[] pbRaw = sha256.ComputeHash(pbKeyData);
m_pbKey = new ProtectedBinary(true, pbRaw);
}
else m_pbKey = new ProtectedBinary(true, pbKeyData);
}
示例7: KcpUserAccount
/// <summary>
/// Construct a user account key.
/// </summary>
public KcpUserAccount()
{
// Test if ProtectedData is supported -- throws an exception
// when running on an old system (Windows 98 / ME).
byte[] pbDummyData = new byte[128];
ProtectedData.Protect(pbDummyData, m_pbEntropy,
DataProtectionScope.CurrentUser);
byte[] pbKey = LoadUserKey(false);
if(pbKey == null) pbKey = CreateUserKey();
if(pbKey == null) throw new SecurityException(KLRes.UserAccountKeyError);
m_pbKeyData = new ProtectedBinary(true, pbKey);
Array.Clear(pbKey, 0, pbKey.Length);
}
示例8: KcpUserAccount
/// <summary>
/// Construct a user account key.
/// </summary>
public KcpUserAccount()
{
// Test if ProtectedData is supported -- throws an exception
// when running on an old system (Windows 98 / ME).
byte[] pbDummyData = new byte[128];
ProtectedData.Protect(pbDummyData, m_pbEntropy,
DataProtectionScope.CurrentUser);
byte[] pbKey = LoadUserKey(false);
if(pbKey == null) pbKey = CreateUserKey();
if(pbKey == null) // Should never happen
{
Debug.Assert(false);
throw new SecurityException(KLRes.UserAccountKeyError);
}
m_pbKeyData = new ProtectedBinary(true, pbKey);
MemUtil.ZeroByteArray(pbKey);
}
示例9: Init
private void Init(bool bEnableProtection, byte[] pbUtf8)
{
if(pbUtf8 == null) throw new ArgumentNullException("pbUtf8");
m_bIsProtected = bEnableProtection;
if(bEnableProtection)
m_pbUtf8 = new ProtectedBinary(true, pbUtf8);
else
m_strPlainText = StrUtil.Utf8.GetString(pbUtf8, 0, pbUtf8.Length);
}
示例10: UpdateKeePassEntry
public static void UpdateKeePassEntry(PwEntry entry,
string username = "",
string title = "",
string url = "",
string notes = "",
string password = "",
string[] attachments = null,
string[] tags = null)
{
UpdateValue(entry, "UserName", username);
UpdateValue(entry, "Title", title);
UpdateValue(entry, "URL", url);
UpdateValue(entry, "Notes", notes);
UpdateValue(entry, "Password", password);
if(tags != null)
{
var tagsCopy = entry.Tags.ToArray();
foreach(var tag in tagsCopy)
entry.RemoveTag(tag);
foreach (var tag in tags)
entry.AddTag(tag);
}
if (attachments != null)
{
var fileNames = attachments.Select(o => Path.GetFileName(o)).ToList();
var binaries = entry.Binaries.CloneDeep();
var filesToAdd = new List<string>();
foreach(var binary in binaries)
{
entry.Binaries.Remove(binary.Key);
}
foreach(var attachment in attachments)
{
var fileName = Path.GetFileName(attachment);
var bytes = File.ReadAllBytes(attachment);
if(bytes != null)
{
var protectedBytes = new ProtectedBinary(true, bytes);
entry.Binaries.Set(fileName, protectedBytes);
}
}
}
}
示例11: Construct
private void Construct(IOConnectionInfo iocFile)
{
byte[] pbKey = LoadXmlKeyFile(iocFile);
if(pbKey == null) pbKey = LoadKeyFile(iocFile);
if(pbKey == null) throw new InvalidOperationException();
m_strPath = iocFile.Path;
m_pbKeyData = new ProtectedBinary(true, pbKey);
}
示例12: OnCtxBinNew
private void OnCtxBinNew(object sender, EventArgs e)
{
if(m_pwEditMode == PwEditMode.ViewReadOnlyEntry) return;
string strName;
for(int i = 0; ; ++i)
{
strName = KPRes.New;
if(i >= 1) strName += " (" + i.ToString() + ")";
strName += ".rtf";
if(m_vBinaries.Get(strName) == null) break;
}
ProtectedBinary pb = new ProtectedBinary();
m_vBinaries.Set(strName, pb);
UpdateEntryBinaries(false, true, strName);
ResizeColumnHeaders();
ListViewItem lviNew = m_lvBinaries.FindItemWithText(strName,
false, 0, false);
if(lviNew != null) lviNew.BeginEdit();
}
示例13: BinPoolFind
private string BinPoolFind(ProtectedBinary pb)
{
if(pb == null) { Debug.Assert(false); return null; }
foreach(KeyValuePair<string, ProtectedBinary> kvp in m_dictBinPool)
{
if(pb.Equals(kvp.Value)) return kvp.Key;
}
return null;
}
示例14: ProtectedBinary
/// <summary>
/// Construct a new protected binary data object. Copy the data from
/// an existing object.
/// </summary>
/// <param name="pbTemplate">Existing <c>ProtectedBinary</c> object,
/// which is used to initialize the new object. This parameter must
/// not be <c>null</c>.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the input
/// parameter is <c>null</c>.</exception>
public ProtectedBinary(ProtectedBinary pbTemplate)
{
Debug.Assert(pbTemplate != null); if(pbTemplate == null) throw new ArgumentNullException("pbTemplate");
m_bDoProtect = pbTemplate.m_bDoProtect;
byte[] pbBuf = pbTemplate.ReadData();
SetData(pbBuf);
MemUtil.ZeroByteArray(pbBuf);
}
示例15: BinPoolAdd
private void BinPoolAdd(ProtectedBinary pb)
{
if(pb == null) { Debug.Assert(false); return; }
if(BinPoolFind(pb) != null) return; // Exists already
m_dictBinPool.Add(m_dictBinPool.Count.ToString(), pb);
}