Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollingIvFactory"/> class.
        /// </summary>
        /// <param name="encryptionAlgorithm">The <see cref="ICryptoAlgorithm"/> instance to use for encryption IVs.</param>
        /// <param name="decryptionAlgorithm">The <see cref="ICryptoAlgorithm"/> instance to use for decryption IVs.</param>
        /// <param name="version">The version number to assign to created <see cref="RollingIv"/> instances.</param>
        public RollingIvFactory(ICryptoAlgorithm encryptionAlgorithm, ICryptoAlgorithm decryptionAlgorithm, ushort version)
        {
            _encryptionAlgorithm = encryptionAlgorithm;
            _decryptionAlgorithm = decryptionAlgorithm;

            _version = version;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollingIvFactory"/> class.
        /// </summary>
        /// <param name="symmetricAlgorithm">The <see cref="ICryptoAlgorithm"/> instance to use for both encryption and decryption.</param>
        /// <param name="version">The version number to assign to created <see cref="RollingIv"/> instances.</param>
        public RollingIvFactory(ICryptoAlgorithm symmetricAlgorithm, ushort version)
        {
            this.encryptionAlgorithm = symmetricAlgorithm;
            this.decryptionAlgorithm = symmetricAlgorithm;

            this.version = version;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollingIvFactory"/> class.
        /// </summary>
        /// <param name="encryptionAlgorithm">The <see cref="ICryptoAlgorithm"/> instance to use for encryption IVs.</param>
        /// <param name="decryptionAlgorithm">The <see cref="ICryptoAlgorithm"/> instance to use for decryption IVs.</param>
        /// <param name="version">The version number to assign to created <see cref="RollingIv"/> instances.</param>
        public RollingIvFactory(ICryptoAlgorithm encryptionAlgorithm, ICryptoAlgorithm decryptionAlgorithm, ushort version)
        {
            this.encryptionAlgorithm = encryptionAlgorithm;
            this.decryptionAlgorithm = decryptionAlgorithm;

            this.version = version;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollingIvFactory"/> class.
        /// </summary>
        /// <param name="symmetricAlgorithm">The <see cref="ICryptoAlgorithm"/> instance to use for both encryption and decryption.</param>
        /// <param name="version">The version number to assign to created <see cref="RollingIv"/> instances.</param>
        public RollingIvFactory(ICryptoAlgorithm symmetricAlgorithm, ushort version)
        {
            _encryptionAlgorithm = symmetricAlgorithm;
            _decryptionAlgorithm = symmetricAlgorithm;

            _version = version;
        }
Ejemplo n.º 5
0
 public TokenController(ICryptoAlgorithm crypto, ICache <Authorization> cache, ILogger <TokenController> logger, Config config)
 {
     _Crypto = crypto;
     _Cache  = cache;
     Logger  = logger;
     Config  = config;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollingIv"/> class.
        /// </summary>
        /// <param name="algorithm">The <see cref="ICryptoAlgorithm"/> instance for this session.</param>
        /// <param name="initialIv">The initial IV for this instance.</param>
        /// <param name="versionMask">The version mask used for header creation.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="algorithm"/> or <paramref name="initialIv"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown if <paramref name="initialIv"/> does not have exactly 4 elements.
        /// </exception>
        public RollingIv(ICryptoAlgorithm algorithm, byte[] initialIv, ushort versionMask)
        {
            Guard.NotNull(() => algorithm, algorithm);
            Guard.NotNull(() => initialIv, initialIv);

            if (initialIv.Length != 4)
            {
                throw new ArgumentException(CommonStrings.IvMustBe4Bytes, "initialIv");
            }

            this.algorithm = algorithm;
            this.iv = initialIv.FastClone();

            // Flip the version mask.
            this.versionMask = (ushort)((versionMask >> 8) | ((versionMask & 0xFF) << 8));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollingIv"/> class.
        /// </summary>
        /// <param name="algorithm">The <see cref="ICryptoAlgorithm"/> instance for this session.</param>
        /// <param name="initialIv">The initial IV for this instance.</param>
        /// <param name="versionMask">The version mask used for header creation.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown if <paramref name="algorithm"/> or <paramref name="initialIv"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown if <paramref name="initialIv"/> does not have exactly 4 elements.
        /// </exception>
        public RollingIv(ICryptoAlgorithm algorithm, byte[] initialIv, ushort versionMask)
        {
            Guard.NotNull(() => algorithm, algorithm);
            Guard.NotNull(() => initialIv, initialIv);

            if (initialIv.Length != 4)
            {
                throw new ArgumentException(CommonStrings.IvMustBe4Bytes, nameof(initialIv));
            }

            _algorithm = algorithm;
            _iv        = initialIv.FastClone();

            // Flip the version mask.
            _versionMask = (ushort)((versionMask >> 8) | ((versionMask & 0xFF) << 8));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModel"/> class.
        /// </summary>
        public ViewModel()
        {
            // symmetric algorithms
            this.algorithms.Add(new Crypto(true, "Advanced Encryption Standard: Cipher Block Chaining", SymmetricAlgorithmNames.AesCbc));
            this.algorithms.Add(new Crypto(true, "Advanced Encryption Standard: Electronic Code Book", SymmetricAlgorithmNames.AesEcb));
            this.algorithms.Add(new Crypto(true, "Data Encryption Standard: Cipher Block Chaining", SymmetricAlgorithmNames.DesCbc));
            this.algorithms.Add(new Crypto(true, "Rivest Cipher v2: Electronic Code Book", SymmetricAlgorithmNames.Rc2Ecb));
            this.algorithms.Add(new Crypto(true, "Triple Data Encryption Standard: Cipher Block Chaining", SymmetricAlgorithmNames.TripleDesCbc));

            // symmetric algorithms with PKCS#7
            this.algorithms.Add(new Crypto(true, "Advanced Encryption Standard: Cipher Block Chaining with PKCS#7", SymmetricAlgorithmNames.AesCbcPkcs7));
            this.algorithms.Add(new Crypto(true, "Data Encryption Standard: Cipher Block Chaining with PKCS#7", SymmetricAlgorithmNames.DesCbcPkcs7));
            this.algorithms.Add(new Crypto(true, "Rivest Cipher v2: Cipher Block Chaining with PKCS#7", SymmetricAlgorithmNames.Rc2CbcPkcs7));
            this.algorithms.Add(new Crypto(true, "Triple Data Encryption Standard: Cipher Block Chaining with PKCS#7", SymmetricAlgorithmNames.TripleDesCbcPkcs7));

            // authenticated symmetric algorithms
            this.algorithms.Add(new Crypto(true, "Advanced Encryption Standard: Galois/Counter Mode", SymmetricAlgorithmNames.AesGcm));
            this.algorithms.Add(new Crypto(true, "Advanced Encryption Standard: Counter with CBC-MAC", SymmetricAlgorithmNames.AesCcm));

            // stream cipher
            this.algorithms.Add(new Crypto(true, "Rivest Cipher v4 (RC4)", SymmetricAlgorithmNames.Rc4));

            // asymmetric algorithm example
            this.algorithms.Add(new Crypto(false, "Ron Rivest, Adi Shamir, and Leonard Adleman (RSA) PKCS#1", AsymmetricAlgorithmNames.RsaPkcs1));

            // hash algorithms
            this.algorithms.Add(new Crypto(true, "Message Digest 5 (MD5)", HashAlgorithmNames.Md5));
            this.algorithms.Add(new Crypto(true, "Secure Hash Algorithm 1 (SHA1)", HashAlgorithmNames.Sha1));
            this.algorithms.Add(new Crypto(true, "Secure Hash Algorithm 256-bit (SHA2)", HashAlgorithmNames.Sha256));
            this.algorithms.Add(new Crypto(true, "Secure Hash Algorithm 512-bit (SHA2)", HashAlgorithmNames.Sha512));

            // MAC algorithms
            this.algorithms.Add(new Crypto(true, "Hash-based Message Authentication Code with Message Digest", MacAlgorithmNames.HmacMd5));
            this.algorithms.Add(new Crypto(true, "Hash-based Message Authentication Code with Secure Hash Algorithm 1", MacAlgorithmNames.HmacSha1));
            this.algorithms.Add(new Crypto(true, "Hash-based Message Authentication Code with Secure Hash Algorithm 256-bit (SHA2)", MacAlgorithmNames.HmacSha256));
            this.algorithms.Add(new Crypto(true, "Hash-based Message Authentication Code with Secure Hash Algorithm 512-bit (SHA2)", MacAlgorithmNames.HmacSha512));

            this.selectedAlgorithm = this.algorithms[0];
            this.encryptionInput   = "Overwrite this with the text you wish to secure.";
            this.decryptionInput   = "Overwrite this with the encrypted text you wish to decode or the signature to verify.";
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="algorithm">The crypto alogrithm</param>
        /// <param name="from">This source stream</param>
        /// <param name="to">The destination stream</param>
        /// <param name="mode">The crypto mode</param>
        /// <param name="chunkSize">The encryption chunk size</param>
        public CryptoDirector(ICryptoAlgorithm algorithm, Stream from, Stream to, RedirectionMode mode, uint chunkSize = 1024 * 1024)
        {
            /**     Validate required parameters    **/
            if (algorithm == null)
            {
                throw new ArgumentNullException("algorithm");
            }
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }

            /**     Initiaize private fileds **/
            _algorithm = algorithm;
            _from      = from;
            _to        = to;
            _chunkSize = chunkSize;
            _mode      = mode;
        }
Ejemplo n.º 10
0
 public CryptoHasher(ICryptoAlgorithm algorithm)
 {
     _algorithm = algorithm;
 }
Ejemplo n.º 11
0
 public SettingsDecryptor(ICryptoAlgorithm crypto)
 {
     _crypto = crypto ?? throw new ArgumentNullException(nameof(crypto));
 }
Ejemplo n.º 12
0
        public void SetCryptoAlgorithm(ICryptoAlgorithm algorithm)
        {
            this.algorithm = algorithm;

            //throw new NotImplementedException();
        }
Ejemplo n.º 13
0
 public void SetCryptoAlgorithm(ICryptoAlgorithm algorithm)
 {
     cryptoAlgorithm = algorithm;
 }
Ejemplo n.º 14
0
 public Token(ICryptoAlgorithm algorithm)
 {
     _Algorithm = algorithm;
 }
 public EncryptedKeyPair(ICryptoAlgorithm cryptoAlgorithm)
 {
     CryptoAlgorithm = cryptoAlgorithm;
 }
Ejemplo n.º 16
0
 public SettingsDecryptor(ICryptoAlgorithm crypto) : base(crypto)
 {
 }
Ejemplo n.º 17
0
 protected SettingsDecryptorBase(ICryptoAlgorithm crypto)
 {
     _crypto = crypto ?? throw new ArgumentNullException(nameof(crypto));
 }