本文整理汇总了C#中KeePassLib.Security.ProtectedBinary类的典型用法代码示例。如果您正苦于以下问题:C# ProtectedBinary类的具体用法?C# ProtectedBinary怎么用?C# ProtectedBinary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProtectedBinary类属于KeePassLib.Security命名空间,在下文中一共展示了ProtectedBinary类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:jonbws,项目名称:strengthreport,代码行数:8,代码来源:KcpCustomKey.cs
示例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);
}
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:10,代码来源:KcpKeyFile.cs
示例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);
}
开发者ID:ComradeP,项目名称:KeePass-2.x,代码行数:11,代码来源:KcpPassword.cs
示例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;
}
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:12,代码来源:KcpPassword.cs
示例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);
}
开发者ID:joshuadugie,项目名称:KeePass-2.x,代码行数:14,代码来源:KcpPassword.cs
示例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);
}
开发者ID:elitak,项目名称:keepass,代码行数:15,代码来源:KcpCustomKey.cs
示例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);
}
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:18,代码来源:KcpUserAccount.cs
示例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);
}
开发者ID:cappert,项目名称:keepass2,代码行数:22,代码来源:KcpUserAccount.cs
示例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);
}
开发者ID:riking,项目名称:go-keepass2,代码行数:11,代码来源:ProtectedString.cs
示例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);
}
}
}
}
开发者ID:badmishkallc,项目名称:jolt9-devops,代码行数:49,代码来源:Util.cs
示例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);
}
开发者ID:amiryal,项目名称:keepass2,代码行数:10,代码来源:KcpKeyFile.cs
示例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();
}
开发者ID:rdealexb,项目名称:keepass,代码行数:23,代码来源:PwEntryForm.cs
示例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;
}
开发者ID:saadware,项目名称:kpn,代码行数:11,代码来源:KdbxFile.cs
示例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);
}
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:19,代码来源:ProtectedBinary.cs
示例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);
}
开发者ID:saadware,项目名称:kpn,代码行数:8,代码来源:KdbxFile.cs
示例16: SaveBinary
private static void SaveBinary(string strName, ProtectedBinary pb,
string strSaveDir)
{
if(pb == null) { Debug.Assert(false); return; }
if(string.IsNullOrEmpty(strName)) strName = "File.bin";
string strPath;
int iTry = 1;
do
{
strPath = UrlUtil.EnsureTerminatingSeparator(strSaveDir, false);
string strExt = UrlUtil.GetExtension(strName);
string strDesc = UrlUtil.StripExtension(strName);
strPath += strDesc;
if(iTry > 1) strPath += " (" + iTry.ToString() + ")";
if(!string.IsNullOrEmpty(strExt)) strPath += "." + strExt;
++iTry;
}
while(File.Exists(strPath));
#if !KeePassLibSD
byte[] pbData = pb.ReadData();
File.WriteAllBytes(strPath, pbData);
MemUtil.ZeroByteArray(pbData);
#else
FileStream fs = new FileStream(strPath, FileMode.Create,
FileAccess.Write, FileShare.None);
byte[] pbData = pb.ReadData();
fs.Write(pbData, 0, pbData.Length);
fs.Close();
#endif
}
开发者ID:saadware,项目名称:kpn,代码行数:37,代码来源:KdbxFile.cs
示例17: Construct
private void Construct(IOConnectionInfo iocFile)
{
byte[] pbFileData = IOConnection.ReadFile(iocFile);
if(pbFileData == null) throw new FileNotFoundException();
byte[] pbKey = LoadXmlKeyFile(pbFileData);
if(pbKey == null) pbKey = LoadKeyFile(pbFileData);
if(pbKey == null) throw new InvalidOperationException();
m_strPath = iocFile.Path;
m_pbKeyData = new ProtectedBinary(true, pbKey);
MemUtil.ZeroByteArray(pbKey);
}
开发者ID:eis,项目名称:keepass-eis-flavored,代码行数:15,代码来源:KcpKeyFile.cs
示例18: GenerateKey32
/// <summary>
/// Generate a 32-bit wide key out of the composite key.
/// </summary>
/// <param name="pbKeySeed32">Seed used in the key transformation
/// rounds. Must be a byte array containing exactly 32 bytes; must
/// not be null.</param>
/// <param name="uNumRounds">Number of key transformation rounds.</param>
/// <returns>Returns a protected binary object that contains the
/// resulting 32-bit wide key.</returns>
public ProtectedBinary GenerateKey32(byte[] pbKeySeed32, ulong uNumRounds)
{
Debug.Assert(pbKeySeed32 != null);
if(pbKeySeed32 == null) throw new ArgumentNullException("pbKeySeed32");
Debug.Assert(pbKeySeed32.Length == 32);
if(pbKeySeed32.Length != 32) throw new ArgumentException("pbKeySeed32");
byte[] pbRaw32 = CreateRawCompositeKey32();
if((pbRaw32 == null) || (pbRaw32.Length != 32))
{ Debug.Assert(false); return null; }
byte[] pbTrf32 = TransformKey(pbRaw32, pbKeySeed32, uNumRounds);
if((pbTrf32 == null) || (pbTrf32.Length != 32))
{ Debug.Assert(false); return null; }
ProtectedBinary pbRet = new ProtectedBinary(true, pbTrf32);
MemUtil.ZeroByteArray(pbTrf32);
MemUtil.ZeroByteArray(pbRaw32);
return pbRet;
}
开发者ID:rassilon,项目名称:keepass,代码行数:30,代码来源:CompositeKey.cs
示例19: ReadEntry
private static void ReadEntry(XmlNode xmlNode, PwDatabase pwStorage)
{
PwEntry pe = new PwEntry(true, true);
PwGroup pg = pwStorage.RootGroup;
string strAttachDesc = null, strAttachment = null;
foreach(XmlNode xmlChild in xmlNode)
{
if(xmlChild.Name == ElemGroup)
{
string strPreTree = null;
try
{
XmlNode xmlTree = xmlChild.Attributes.GetNamedItem(AttribGroupTree);
strPreTree = xmlTree.Value;
}
catch(Exception) { }
string strLast = XmlUtil.SafeInnerText(xmlChild);
string strGroup = ((!string.IsNullOrEmpty(strPreTree)) ?
strPreTree + "\\" + strLast : strLast);
pg = pwStorage.RootGroup.FindCreateSubTree(strGroup,
new string[1]{ "\\" }, true);
}
else if(xmlChild.Name == ElemTitle)
pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
pwStorage.MemoryProtection.ProtectTitle,
XmlUtil.SafeInnerText(xmlChild)));
else if(xmlChild.Name == ElemUserName)
pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
pwStorage.MemoryProtection.ProtectUserName,
XmlUtil.SafeInnerText(xmlChild)));
else if(xmlChild.Name == ElemUrl)
pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
pwStorage.MemoryProtection.ProtectUrl,
XmlUtil.SafeInnerText(xmlChild)));
else if(xmlChild.Name == ElemPassword)
pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(
pwStorage.MemoryProtection.ProtectPassword,
XmlUtil.SafeInnerText(xmlChild)));
else if(xmlChild.Name == ElemNotes)
pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
pwStorage.MemoryProtection.ProtectNotes,
XmlUtil.SafeInnerText(xmlChild)));
else if(xmlChild.Name == ElemUuid)
pe.SetUuid(new PwUuid(MemUtil.HexStringToByteArray(
XmlUtil.SafeInnerText(xmlChild))), false);
else if(xmlChild.Name == ElemImage)
{
int nImage;
if(int.TryParse(XmlUtil.SafeInnerText(xmlChild), out nImage))
{
if((nImage >= 0) && (nImage < (int)PwIcon.Count))
pe.IconId = (PwIcon)nImage;
else { Debug.Assert(false); }
}
else { Debug.Assert(false); }
}
else if(xmlChild.Name == ElemCreationTime)
pe.CreationTime = ParseTime(XmlUtil.SafeInnerText(xmlChild));
else if(xmlChild.Name == ElemLastModTime)
pe.LastModificationTime = ParseTime(XmlUtil.SafeInnerText(xmlChild));
else if(xmlChild.Name == ElemLastAccessTime)
pe.LastAccessTime = ParseTime(XmlUtil.SafeInnerText(xmlChild));
else if(xmlChild.Name == ElemExpiryTime)
{
try
{
XmlNode xmlExpires = xmlChild.Attributes.GetNamedItem(AttribExpires);
if(StrUtil.StringToBool(xmlExpires.Value))
{
pe.Expires = true;
pe.ExpiryTime = ParseTime(XmlUtil.SafeInnerText(xmlChild));
}
else { Debug.Assert(ParseTime(XmlUtil.SafeInnerText(xmlChild)).Year == 2999); }
}
catch(Exception) { Debug.Assert(false); }
}
else if(xmlChild.Name == ElemAttachDesc)
strAttachDesc = XmlUtil.SafeInnerText(xmlChild);
else if(xmlChild.Name == ElemAttachment)
strAttachment = XmlUtil.SafeInnerText(xmlChild);
else { Debug.Assert(false); }
}
if(!string.IsNullOrEmpty(strAttachDesc) && (strAttachment != null))
{
byte[] pbData = Convert.FromBase64String(strAttachment);
ProtectedBinary pb = new ProtectedBinary(false, pbData);
pe.Binaries.Set(strAttachDesc, pb);
}
pg.AddEntry(pe, true);
}
开发者ID:Stoom,项目名称:KeePass,代码行数:96,代码来源:KeePassXml1x.cs
示例20: ReadEntry
private static void ReadEntry(XmlNode xmlNode, PwGroup pgParent,
PwDatabase pwStorage)
{
PwEntry pe = new PwEntry(true, true);
pgParent.AddEntry(pe, true);
string strAttachDesc = null, strAttachment = null;
foreach(XmlNode xmlChild in xmlNode)
{
if(xmlChild.Name == ElemTitle)
pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
pwStorage.MemoryProtection.ProtectTitle,
XmlUtil.SafeInnerText(xmlChild)));
else if(xmlChild.Name == ElemUserName)
pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
pwStorage.MemoryProtection.ProtectUserName,
XmlUtil.SafeInnerText(xmlChild)));
else if(xmlChild.Name == ElemUrl)
pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
pwStorage.MemoryProtection.ProtectUrl,
XmlUtil.SafeInnerText(xmlChild)));
else if(xmlChild.Name == ElemPassword)
pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(
pwStorage.MemoryProtection.ProtectPassword,
XmlUtil.SafeInnerText(xmlChild)));
else if(xmlChild.Name == ElemNotes)
pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
pwStorage.MemoryProtection.ProtectNotes,
FilterSpecial(XmlUtil.SafeInnerXml(xmlChild))));
else if(xmlChild.Name == ElemIcon)
pe.IconId = ReadIcon(xmlChild, pe.IconId);
else if(xmlChild.Name == ElemCreationTime)
pe.CreationTime = ParseTime(XmlUtil.SafeInnerText(xmlChild));
else if(xmlChild.Name == ElemLastModTime)
pe.LastModificationTime = ParseTime(XmlUtil.SafeInnerText(xmlChild));
else if(xmlChild.Name == ElemLastAccessTime)
pe.LastAccessTime = ParseTime(XmlUtil.SafeInnerText(xmlChild));
else if(xmlChild.Name == ElemExpiryTime)
{
string strDate = XmlUtil.SafeInnerText(xmlChild);
pe.Expires = (strDate != ValueNever);
if(pe.Expires) pe.ExpiryTime = ParseTime(strDate);
}
else if(xmlChild.Name == ElemAttachDesc)
strAttachDesc = XmlUtil.SafeInnerText(xmlChild);
else if(xmlChild.Name == ElemAttachment)
strAttachment = XmlUtil.SafeInnerText(xmlChild);
else { Debug.Assert(false); }
}
if(!string.IsNullOrEmpty(strAttachDesc) && (strAttachment != null))
{
byte[] pbData = Convert.FromBase64String(strAttachment);
ProtectedBinary pb = new ProtectedBinary(false, pbData);
pe.Binaries.Set(strAttachDesc, pb);
}
}
开发者ID:eis,项目名称:keepass-eis-flavored,代码行数:58,代码来源:KeePassXXml041.cs
注:本文中的KeePassLib.Security.ProtectedBinary类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论