Beispiel #1
0
        public byte[] ToAdditionalAuthenticatedData()
        {
            string data = String.Format("{0}.{1}.{2}", Header.ToBase64String(),
                                        EncryptedMasterKey.ToBase64String(),
                                        InitializationVector.ToBase64String());

            return(Encoding.UTF8.GetBytes(data));
        }
Beispiel #2
0
 protected bool Equals(CiphertextDto other)
 {
     return(Id.Equals(other.Id) &&
            Ciphertext.SequenceEqual(other.Ciphertext) &&
            InitializationVector.SequenceEqual(other.InitializationVector) &&
            Salt.SequenceEqual(other.Salt) &&
            Deleted.Equals(other.Deleted));
 }
Beispiel #3
0
 public override string ToString()
 {
     return(String.Format("{0}.{1}.{2}.{3}.{4}", Header.ToBase64String(),
                          EncryptedMasterKey.ToBase64String(),
                          InitializationVector.ToBase64String(),
                          CipherText.ToBase64String(),
                          Tag.ToBase64String()));
 }
        public void ShuffleProvidesExpectedResult()
        {
            var iv = new InitializationVector(0);

            CollectionAssert.AreEqual(new byte[4], iv.Bytes);
            iv.Shuffle();
            CollectionAssert.AreEqual(new byte[] { 0x11, 0xBB, 0x64, 0xC7 }, iv.Bytes);
        }
        public void MaxValueIvCastsSuccessfully()
        {
            var iv = new InitializationVector(uint.MaxValue);

            Assert.AreEqual(ushort.MaxValue, iv.HiWord);
            Assert.AreEqual(ushort.MaxValue, iv.LoWord);
            CollectionAssert.AreEqual(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }, iv.Bytes);
            Assert.AreEqual(uint.MaxValue, iv.UInt);
        }
        public void ZeroValueIvCastsSuccessfully()
        {
            var iv = new InitializationVector(0);

            Assert.AreEqual(0, iv.HiWord);
            Assert.AreEqual(0, iv.LoWord);
            CollectionAssert.AreEqual(new byte[4], iv.Bytes);
            Assert.AreEqual(0u, iv.UInt);
        }
Beispiel #7
0
 /// <summary>
 /// Convert this payload to Base64Url string
 /// </summary>
 /// <returns></returns>
 public string SerializeToBase64UrlString()
 {
     return(String.Format("{0}.{1}.{2}.{3}.{4}",
                          Header.GetBase64UrlFromNormalString(),
                          EncryptedMasterKey.ToBase64UrlString(),
                          InitializationVector.ToBase64UrlString(),
                          CipherText.ToBase64UrlString(),
                          Tag.ToBase64UrlString()
                          ));
 }
Beispiel #8
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = Id.GetHashCode();
         hashCode = (hashCode * 397) ^ (Ciphertext != null ? Ciphertext.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (InitializationVector != null ? InitializationVector.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Salt != null ? Salt.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Deleted.GetHashCode();
         return(hashCode);
     }
 }
        public override void Write()
        {
            using (StreamWriter keyFile =
                       new StreamWriter(Environment.CurrentDirectory + Constants.File.Path.SECRET_KEY + FileName))
            {
                keyFile.WriteLine(Constants.START);
                keyFile.WriteLine();

                keyFile.WriteLine(Constants.DESCRIPTION);
                keyFile.WriteLine(Constants.TAB + Constants.DESCRIPTION_SECRET_KEY);
                keyFile.WriteLine();

                keyFile.WriteLine(Constants.METHOD);
                foreach (var m in Methods)
                {
                    keyFile.WriteLine(Constants.TAB + m); // "SHA-1"
                }
                keyFile.WriteLine();

                keyFile.WriteLine(Constants.KEY_LENGTH);
                foreach (var m in KeyLength)
                {
                    keyFile.WriteLine(Constants.TAB + m); // "SHA-1"
                }
                keyFile.WriteLine();

                keyFile.WriteLine(Constants.SECRET_KEY);
                for (int i = 0; i < GetNumberOfLines(SecretKey.Length); i++)
                {
                    if ((SecretKey.Length - i * Constants.ROW__CHARACTER_COUNT) < Constants.ROW__CHARACTER_COUNT)
                    {
                        keyFile.WriteLine(Constants.TAB + SecretKey.Substring(i * Constants.ROW__CHARACTER_COUNT,
                                                                              (SecretKey.Length - i * Constants.ROW__CHARACTER_COUNT)));
                    }
                    else
                    {
                        keyFile.WriteLine(Constants.TAB + SecretKey.Substring(i * Constants.ROW__CHARACTER_COUNT,
                                                                              Constants.ROW__CHARACTER_COUNT));
                    }
                }
                keyFile.WriteLine();


                keyFile.WriteLine(Constants.INIT_VECTOR);
                for (int i = 0; i < GetNumberOfLines(InitializationVector.Length); i++)
                {
                    if ((InitializationVector.Length - i * Constants.ROW__CHARACTER_COUNT) <
                        Constants.ROW__CHARACTER_COUNT)
                    {
                        keyFile.WriteLine(Constants.TAB + InitializationVector.Substring(
                                              i * Constants.ROW__CHARACTER_COUNT,
                                              (InitializationVector.Length - i * Constants.ROW__CHARACTER_COUNT)));
                    }
                    else
                    {
                        keyFile.WriteLine(Constants.TAB +
                                          InitializationVector.Substring(i * Constants.ROW__CHARACTER_COUNT,
                                                                         Constants.ROW__CHARACTER_COUNT));
                    }
                }
                keyFile.WriteLine();

                keyFile.WriteLine(Constants.END);
            }
        }