internal HMacDRBGProvider(FipsDigestAlgorithm algorithm, byte[] nonce, byte[] personalizationString, int securityStrength, byte[] primaryAdditionalInput) { CryptoStatus.IsReady(); this.hMac = FipsShs.CreateHmac(algorithm); this.nonce = nonce; this.personalizationString = personalizationString; this.securityStrength = securityStrength; this.primaryAdditionalInput = primaryAdditionalInput; }
public CTRDRBGProvider(Org.BouncyCastle.Crypto.Internal.IBlockCipher blockCipher, int keySizeInBits, byte[] nonce, byte[] personalizationString, int securityStrength, byte[] primaryAdditionalInput) { CryptoStatus.IsReady(); this.blockCipher = blockCipher; this.keySizeInBits = keySizeInBits; this.nonce = nonce; this.personalizationString = personalizationString; this.securityStrength = securityStrength; this.primaryAdditionalInput = primaryAdditionalInput; }
public static bool CheckRoleOpened(byte?value, CryptoStatus flag) { if (!value.HasValue || value.Value == 0) { return(false); } CryptoStatus validate = (CryptoStatus)Enum.Parse(typeof(CryptoStatus), value.Value.ToString()); return((validate & flag) != 0); }
internal Builder(FipsAlgorithm algorithm, FipsDigestAlgorithm digestAlg, Variations variation, SecureRandom random, IEntropySourceProvider entropySourceProvider) { CryptoStatus.IsReady(); this.algorithm = algorithm; this.digestAlg = digestAlg; this.variation = variation; this.random = random; this.entropySourceProvider = entropySourceProvider; }
internal GeneralBlockCipherProvider(string name, IEngineProvider <Internal.IBlockCipher> engineProvider) { CryptoStatus.IsReady(); if (CryptoServicesRegistrar.IsInApprovedOnlyMode()) { throw new CryptoUnapprovedOperationError("Attempt to create provider for unapproved algorithm in approved only mode"); } this.name = name; this.engineProvider = engineProvider; }
public void ChooseMode(CryptoStatus status) { switch (status) { case CryptoStatus.File: Message = File.ReadAllText(Directory.GetCurrentDirectory() + "\\Files\\Information.txt"); break; case CryptoStatus.Personal: Console.WriteLine("Enter Informations to encrypt"); Message = Console.ReadLine(); break; } }
public ActionResult Save(Cryptocurrencies cur) { var roleStr = Request.Form["moduleperm"]; CryptoStatus role = new CryptoStatus(); if (!string.IsNullOrWhiteSpace(roleStr)) { roleStr.Split(',').ToList().ForEach(a => { role = role | (CryptoStatus)Enum.Parse(typeof(CryptoStatus), a); }); } cur.Status = role; //上传图片 HttpPostedFileBase IconFile = Request.Files["Icon"]; if (IconFile.ContentLength != 0) { cur.IconURL = new Guid(new Utils.FileUploader().UpImageToCDN(IconFile)); } SaveResult result = new SaveResult(); var statusList = new List <SelectListItem>(); statusList.Add(new SelectListItem() { Text = "Enable", Value = "1" }); statusList.Add(new SelectListItem() { Text = "Disable", Value = "0" }); ViewBag.StatusList = statusList; var boolList = new List <SelectListItem>(); boolList.Add(new SelectListItem() { Text = "True", Value = "1" }); boolList.Add(new SelectListItem() { Text = "False", Value = "0" }); ViewBag.BoolList = boolList; if (cur.Id > 0)//编辑 { SaveEdit(cur); Cryptocurrencies oldCur = FoundationDB.CryptocurrencyDb.GetById(cur.Id); Dictionary <string, bool> roleDic = new Dictionary <string, bool>(); foreach (var item in EnumHelper.EnumToList <CryptoStatus>()) { roleDic.Add(item.EnumName, CheckRoleOpened((byte)oldCur.Status, (CryptoStatus)item.EnumValue)); } ViewBag.RoleDic = roleDic; List <PriceInfoViewModel> priceList = new List <PriceInfoViewModel>(); priceList = FoundationDB.DB.Queryable <Currency, PriceInfos>((c, pi) => new object[] { JoinType.Left, c.ID == pi.CurrencyID }).Where((c, pi) => pi.CryptoID == cur.Id).Select((c, pi) => new PriceInfoViewModel { CurrencyName = c.Name, CurrencyCode = c.Code, Price = pi.Price }).ToList(); ViewBag.PriceList = priceList; return(View("Edit", oldCur)); } else//新增 { int newId = SaveCreate(cur).Data; Cryptocurrencies newCur = FoundationDB.CryptocurrencyDb.GetById(newId); Dictionary <string, bool> roleDic = new Dictionary <string, bool>(); foreach (var item in EnumHelper.EnumToList <CryptoStatus>()) { roleDic.Add(item.EnumName, CheckRoleOpened((byte)newCur.Status, (CryptoStatus)item.EnumValue)); } ViewBag.RoleDic = roleDic; List <PriceInfoViewModel> priceList = new List <PriceInfoViewModel>(); priceList = FoundationDB.DB.Queryable <Currency, PriceInfos>((c, pi) => new object[] { JoinType.Left, c.ID == pi.CurrencyID }).Where((c, pi) => pi.CryptoID == newId).Select((c, pi) => new PriceInfoViewModel { CurrencyName = c.Name, CurrencyCode = c.Code, Price = pi.Price }).ToList(); ViewBag.PriceList = priceList; return(View("Edit", newCur)); } }
public static string StatusMessage(CryptoStatus status) { switch (status) { case CryptoStatus.MissingHeader: return "The file was missing its standard header."; case CryptoStatus.VerificationFailed: return "The message authentication codes were mismatched. The file may have been corrupted or tampered with."; case CryptoStatus.DecodingError: return "There was a problem decoding the file; either the password was invalid or the file may be corrupt."; case CryptoStatus.UnsupportedVersion: return "Unsupported database version."; case CryptoStatus.UnknownError: return "An unknown error occurred while decoding the file."; default: return string.Empty; } }
public static string Decrypt(string data, string password, out CryptoStatus error) { try { using (StringReader reader = new StringReader(data)) { // Read the actual header line and store the expected prefix string actualHeaderLine = reader.ReadLine(); string headerLine = string.Format(CultureInfo.InvariantCulture, "{0} ", HEADER); // If the actual header is less than (or equal!) to our expected one, there is no version // and is thus invalid, OR if the actual header doesn't start with our header, it's invalid if (actualHeaderLine.Length <= headerLine.Length || !actualHeaderLine.StartsWith(headerLine)) { error = CryptoStatus.MissingHeader; return string.Empty; } // Everything after the "SILVERLOCK DATABASE FILE" string[] theRest = actualHeaderLine.Substring(actualHeaderLine.Length - (actualHeaderLine.Length - headerLine.Length)).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (theRest.Length == 2) { Version version = new Version(theRest[0]); if (version != Database.Version) { error = CryptoStatus.UnsupportedVersion; return string.Empty; } } else { error = CryptoStatus.MissingHeader; return string.Empty; } error = CryptoStatus.NoError; return Decrypt(password, new EncryptedData(reader.ReadLine(), reader.ReadLine(), reader.ReadToEnd())); } } catch (MACException) { error = CryptoStatus.VerificationFailed; return string.Empty; } catch (CryptographicException) { error = CryptoStatus.DecodingError; return string.Empty; } catch { error = CryptoStatus.UnknownError; return string.Empty; } }
public static string Encrypt(string data, string password, int compressionLevel, out CryptoStatus error) { try { EncryptedData encData = Encrypt(password, data, compressionLevel); StringBuilder builder = new StringBuilder(); builder.AppendFormat(CultureInfo.InvariantCulture, "{0} {1} {2}\n", HEADER, Database.Version, compressionLevel != 0 ? COMPRESSED : UNCOMPRESSED); builder.Append(encData.SaltString + "\n"); builder.Append(encData.MACString + "\n"); builder.Append(encData.DataString + "\n"); error = CryptoStatus.NoError; return builder.ToString(); } catch { error = CryptoStatus.UnknownError; return string.Empty; } }
internal A CreateBuilder <A>(IBuilderServiceType <A> type) { CryptoStatus.IsReady(); return((type as IBuilderService <A>).GetFunc(this).Invoke(type as IParameters <Algorithm>)); }
internal A CreateGenerator <A>(IGenerationServiceType <A> type, SecureRandom random) { CryptoStatus.IsReady(); return((type as IGenerationService <A>).GetFunc(this).Invoke(type as IParameters <Algorithm>, random)); }
internal A CreateService <A>(ICryptoServiceType <A> type, IAsymmetricKey key, SecureRandom random) { CryptoStatus.IsReady(); return((type as IServiceProvider <A>).GetFunc(this).Invoke(new KeyWithRandom(key, random))); }
internal A CreateService <A>(ICryptoServiceType <A> type, IAsymmetricKey key) { CryptoStatus.IsReady(); return((type as IServiceProvider <A>).GetFunc(this).Invoke(key)); }
internal A CreateService <A>(ICryptoServiceType <A> type) { CryptoStatus.IsReady(); return((type as IServiceProvider <A>).GetFunc(this).Invoke((IKey)type)); }