/// <summary>Initializes a new instance of the <see cref="TfsConnectCommand"/> class.</summary> /// <param name="buildServerAdapter">The build server adapter.</param> /// <param name="crypter">The crypter.</param> public TfsConnectCommand(BuildServerAdapter buildServerAdapter, ICrypter crypter) { this.buildServerAdapter = buildServerAdapter; this.crypter = crypter; buildServerAdapter.PropertyChanged += SettingsViewModelPropertyChanged; }
public IoHandler(IEnumerable <IConfigStore> stores, ValueHandler valueHandler, TimeSpan cacheInterval, ICrypter crypter) { _stores = stores ?? throw new ArgumentNullException(nameof(stores)); _valueHandler = valueHandler ?? throw new ArgumentNullException(nameof(valueHandler)); _cacheInterval = cacheInterval; _crypter = crypter; }
public ExpletiveCommand() { _crypter = new Crypter(); _members = Program.Discord.GetGuildAsync(GuildConfiguration.Id).GetAwaiter().GetResult().Members; _lastUseTime = new Dictionary <ulong, DateTime>(); _timeLimitSecs = 30; _expletiveCommandText = CommandConfiguration.GetCommandText <ExpletiveCommand>(); }
public TokenIssuerMiddlewareBase(RequestDelegate next, ICrypter crypter, TokenIssuerOptions tokenIssuerOptions) { _next = next; _crypter = crypter; _options = tokenIssuerOptions; }
public void InitServer(P2PClient thisServer) { Server?.Dispose(); Server = thisServer; crypter = new RSA(Server, 768); Server.OnDebugMessage += str => OnDebugMessage?.Invoke(this, str); Server.OnMessageSend += p_OnMessageSend; Server.OnConnect += p_OnConnection; Server.OnDisconnect += (_, u) => OnUserDisconnect?.Invoke(this, u); }
/// <summary> /// Initializes a new instance of the <see cref="UnknownRecord" /> class. /// </summary> /// <param name="crypter">The value for the <see cref="UnknownRecord.Crypter" /> property.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="crypter" /> is <see langword="null" />. /// </exception> public UnknownRecord(ICrypter crypter) : base() { if (crypter == null) { throw new ArgumentNullException("crypter"); } this.Crypter = crypter; }
public void SetCrypter(Func <P2PClient, ICrypter> newCrypter, bool needDisconnect = true) { crypter = newCrypter.Invoke(Server); if (needDisconnect) { foreach (var i in Server) { Server.Disconnect(i); } } }
/// <summary> /// Adds an encryption provider /// </summary> public ConfigurationBuilder <T> UseCrypter(ICrypter crypter) { if (crypter == null) { throw new ArgumentNullException(nameof(crypter)); } _crypter = crypter; return(this); }
private static IEnumerable <IEnumerable <byte> > DecryptInternal(ICrypter crypter, IEnumerable <byte> source, byte[] initializingVector) { foreach (var block in source.Batch(crypter.BlockSize)) { var blockArray = block.ToArray(); var decryptOutput = crypter.Decrypt(blockArray); var decrypt = decryptOutput.Xor(initializingVector); yield return(decrypt); initializingVector = blockArray.Xor(decrypt); } }
public static void WriteEndData(this FileInfo fi, object data, string pass, ICrypter crypter = null) { crypter = crypter ?? new RijndaelCrypter(); using (var fs = new FileStream(fi.FullName, FileMode.Append, FileAccess.Write)) { var obj = data.SerializeBinary(pass, crypter); //gets encrypted serialized data. var end_jumpsize = BitConverter.GetBytes((long)obj.Length + sizeof(long)); //size of the jump to the start of the object. var output = obj.Concat(end_jumpsize).ToArray(); //concats the output fs.Position = fs.Length; //goes to the end of the file fs.Write(output, 0, output.Length); //writes it all. } }
public static byte[] SerializeBinary(this object o, string pass, ICrypter crypter = null) { crypter = crypter ?? new RijndaelCrypter(); var bf = new BinaryFormatter(); var ms = new MemoryStream(); bf.Serialize(ms, o); var data = new byte[ms.Length]; ms.Position = 0; ms.Read(data, 0, data.Length); ms.Dispose(); return(crypter.EncryptToBytes(data, pass)); }
public void Decrypt_Different_Version() { c = Crypter.Default(() => "password"); VersionedCrypterProvider provider = vsn => Crypter.Default(() => vsn); // 違うバージョンで読み出しても復号化できる var k1 = KeyValueStorage.Secure("test", "1", provider); k1.Upsert("key", "value"); Assert.AreEqual("value", k1.GetString("key")); var k2 = KeyValueStorage.Secure("test", "2", provider); Assert.AreEqual("value", k2.GetString("key")); // k2 -> k1 k2.Upsert("key2", "value2"); Assert.AreEqual("value2", k1.GetString("key2")); }
public static T DeserializeBinary <T>(this byte[] data, string pass, ICrypter crypter = null) { crypter = crypter ?? new RijndaelCrypter(); data = crypter.DecryptToBytes(data, pass); var bf = new BinaryFormatter(); var ms = new MemoryStream(data); var o = bf.Deserialize(ms); ms.Dispose(); if (typeof(T) != o.GetType()) { throw new InvalidCastException("The deserialized object does not fit to the generic type T."); } return((T)o); }
private static List <ICrypter> InitCryptSeq(uint version, uint blockIV) { ICrypter[] crypt = new ICrypter[4]; crypt[RearrangeCrypter.GetIndex(version)] = new RearrangeCrypter(); crypt[XORCrypter.GetIndex(version)] = new XORCrypter(version); crypt[TableCrypter.GetIndex(version)] = new TableCrypter(version); List <ICrypter> cryptSeq = new List <ICrypter>(); while (blockIV > 0) { ICrypter crypter = crypt[blockIV % 10]; if (crypter != null) { cryptSeq.Add(crypter); } blockIV /= 10; } return(cryptSeq); }
/// <summary> /// Sets the private key to use to decrypt password. The private key is an RSA object. /// </summary> /// <param name="privateKey">The RSA object which has the private key</param> public void SetPrivateKey(RSA privateKey) { _passwordCrypter = new RSAPasswordCrypter(privateKey); }
public string GenerateToken(ICrypter crypter, string key) { return(crypter.Encrypt(JsonConvert.SerializeObject(this), key)); }
public void SetUp() { c = Crypter.Default(() => "password"); }
public TokenIssuerMiddleware(RequestDelegate next, ICrypter crypter, TokenIssuerOptions tokenIssuerOptions) : base(next, crypter, tokenIssuerOptions) { }
public CryptContainerStorage(Stream unpacked, Stream container, ICrypter crypter) { unpackedData = unpacked; containerData = container; _crypter = crypter; }
public static ReadEndDataResult <T> ReadEndData <T>(this FileInfo fi, string pass, ICrypter crypter = null) { crypter = crypter ?? new RijndaelCrypter(); var redr = new ReadEndDataResult <T>() { Crypter = crypter }; try { using (var fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read)) { fs.Position = fs.Length - sizeof(long); var endfile_pos = BitConverter.ToInt64(fs.ReadBytes(8), 0); fs.Position = fs.Length - endfile_pos; redr.Result = fs.ReadBytes(endfile_pos - sizeof(long)).DeserializeBinary <T>(pass, crypter); } } catch (Exception e) { redr.Exception = e; } return(redr); }
public static void WriteEndData(this Stream stream, object data, string pass, ICrypter crypter = null) { crypter = crypter ?? new RijndaelCrypter(); var obj = data.SerializeBinary(pass, crypter); //gets encrypted serialized data. var end_jumpsize = BitConverter.GetBytes((long)obj.Length + sizeof(long)); //size of the jump to the start of the object. var output = obj.Concat(end_jumpsize).ToArray(); //concats the output stream.Position = stream.Length; //goes to the end of the file stream.Write(output, 0, output.Length); //writes it all. }
public static WebToken DecryptToken(string tokenString, ICrypter crypter, string key) { string jsonString = crypter.Decrypt(tokenString, key); return(JsonConvert.DeserializeObject <WebToken>(jsonString)); }
public void Init() { _crypter = new CrypterTest2(); _dictionary = new SymbolDictionary(); }
public TeamTasksTokenIssuerMiddleware(UserManager <TeamTasksUser> userManager, RequestDelegate next, ICrypter crypter, TokenIssuerOptions tokenIssuerOptions) : base(next, crypter, tokenIssuerOptions) { um = userManager; }
/// <summary> /// Initializes a new instance of the <see cref="UnknownRecord" /> class. /// </summary> /// <param name="knownType">The value for the <see cref="RecordBase.KnownType" /> property.</param> /// <param name="crypter">The value for the <see cref="UnknownRecord.Crypter" /> property.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="crypter" /> is <see langword="null" />. /// </exception> protected RecordBase(RecordType knownType, ICrypter crypter) : base(crypter: crypter) { this.KnownType = knownType; }
public Form1() { InitializeComponent(); _crypter = new Crypter(new Coder(dataGridView1)); }
public ResourceServerMiddleware(RequestDelegate next, ICrypter crypter, ResourceServerOptions resourceServerOptions) { _next = next; _crypter = crypter; _resourceServerOptions = resourceServerOptions; }
/// <summary> /// Initializes a new instance of the <see cref="ClientHelloRecord" /> class. /// </summary> /// <param name="crypter">The value for the <see cref="UnknownRecord.Crypter" /> property.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="crypter" /> is <see langword="null" />. /// </exception> public ClientHelloRecord(ICrypter crypter) : base(knownType: RecordType.ClientHello, crypter: crypter) { }
/// <summary> /// Creates instances for a stream. /// </summary> /// <param name="stream">The stream from where to read the data from.</param> /// <param name="crypter">The optional crypter to use.</param> /// <returns>The instances.</returns> /// <exception cref="ArgumentNullException"> /// At least one argument is <see langword="null" />. /// </exception> public static IEnumerable <UnknownRecord> FromStream(NetworkStream stream, ICrypter crypter) { if (stream == null) { throw new ArgumentNullException("stream"); } byte? @byte; byte[] buffer; if ((@byte = stream.WaitAndReadByte()) == null) { yield break; } // version var version = @byte.Value; buffer = stream.WaitAndRead(2); if (buffer.Length != 2) { yield break; } // type var type = buffer.ToUInt16().Value; buffer = stream.WaitAndRead(4); if (buffer.Length != 4) { yield break; } // request ID var requestId = buffer.ToUInt32().Value; buffer = stream.WaitAndRead(4); if (buffer.Length != 4) { yield break; } // content length var contentLength = buffer.ToUInt32().Value; if (contentLength > 1048575) { contentLength = 1048575; } if ((@byte = stream.WaitAndReadByte()) == null) { yield break; } // compression ContentCompression compression; Enum.TryParse <ContentCompression>(@byte.ToString(), out compression); buffer = stream.WaitAndRead((int)contentLength); if (buffer.Length != contentLength) { yield break; } var content = buffer; RecordType knownType; Enum.TryParse <RecordType>(type.ToString(), out knownType); var recordType = Assembly.GetExecutingAssembly() .GetTypes() .Where(x => { var allAttribs = x.GetCustomAttributes(typeof(RecordAttribute), false) .Cast <RecordAttribute>() .ToArray(); if (allAttribs.Length < 1) { return(false); } return(allAttribs.First().Type == knownType); }) .FirstOrDefault(); if (recordType == null) { yield break; } var result = (UnknownRecord)Activator.CreateInstance(type: recordType, args: new object[] { crypter }); result.Compression = compression; result.Crypter = crypter; result.RequestId = requestId; result.Version = version; if (!result.ParseContent(content)) { yield break; } yield return(result); }
public Form1() { InitializeComponent(); _crypter = new Crypter(new VigenerCoder()); }