Example #1
0
        public void StreamTest_SetKey()
        {
            var plaintext = new Byte[256];

            using (var memoryStream = new MemoryStream(new Byte[256]))
            {
                using (var tribble = new Tribble <SHA512>(Sample512BitKey, SHA512.Create()))
                {
                    var ciphertext = new Byte[256];
                    using (ICryptoTransform tribbleTransform = tribble.CreateEncryptor(Sample512BitKey, null))
                    {
                        using (
                            var cryptoStream = new NotClosingCryptoStream(memoryStream, tribbleTransform, CryptoStreamMode.Read))
                        {
                            cryptoStream.Read(ciphertext, 0, 256);
                        }
                    }
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    memoryStream.Write(ciphertext, 0, 256);
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    var thereAndBackAgain = new Byte[256];
                    using (ICryptoTransform tribbleTransform = tribble.CreateDecryptor(Sample512BitKey, null))
                    {
                        using (var cryptoStream = new NotClosingCryptoStream(memoryStream, tribbleTransform, CryptoStreamMode.Read))
                            cryptoStream.Read(thereAndBackAgain, 0, 256);
                    }
                    CollectionAssert.AreEqual(plaintext, thereAndBackAgain);
                }
            }
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Requires({"name != null", "! ( location == null && output == null )", "! ( enableOnTheFlyIndexing && location == null )"}) protected IndexingVariantContextWriter(final String name, final File location, final OutputStream output, final net.sf.samtools.SAMSequenceDictionary refDict, final boolean enableOnTheFlyIndexing)
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
        protected internal IndexingVariantContextWriter(string name, File location, OutputStream output, SAMSequenceDictionary refDict, bool enableOnTheFlyIndexing)
        {
            outputStream = output;
            this.name    = name;
            this.refDict = refDict;

            if (enableOnTheFlyIndexing)
            {
                try
                {
                    idxStream = new LittleEndianOutputStream(new FileOutputStream(Tribble.indexFile(location)));
                    //System.out.println("Creating index on the fly for " + location);
                    indexer = new DynamicIndexCreator(IndexFactory.IndexBalanceApproach.FOR_SEEK_TIME);
                    indexer.initialize(location, indexer.defaultBinSize());
                    positionalOutputStream = new PositionalOutputStream(output);
                    outputStream           = positionalOutputStream;
                }
                catch (IOException ex)
                {
                    // No matter what we keep going, since we don't care if we can't create the index file
                    idxStream = null;
                    indexer   = null;
                    positionalOutputStream = null;
                }
            }
        }
Example #3
0
 public void XOR_1030Bits()
 {
     using (var tribble = new Tribble <SHA512>(Sample512BitKey, SHA512.Create()))
     {
         Byte[] plaintext  = Encoding.ASCII.GetBytes("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eu risus aliquam, dapibus est id, mattis arcu. Vestibulum cras amet.");
         Byte[] ciphertext = tribble.XOR(plaintext);
         tribble.Reset();
         Byte[] thereAndBackAgain = tribble.XOR(ciphertext);
         CollectionAssert.AreEqual(plaintext, thereAndBackAgain);
     }
 }
Example #4
0
 public void XOR_1MData()
 {
     using (var tribble = new Tribble <SHA512>(Sample512BitKey, SHA512.Create()))
     {
         Byte[] plaintext  = new Byte[1024 * 1024];
         Byte[] ciphertext = tribble.XOR(plaintext);
         tribble.Reset();
         Byte[] thereAndBackAgain = tribble.XOR(ciphertext);
         CollectionAssert.AreEqual(plaintext, thereAndBackAgain);
     }
 }
Example #5
0
 public void XOR_520Bits()
 {
     using (var tribble = new Tribble <SHA512>(Sample512BitKey, SHA512.Create()))
     {
         Byte[] plaintext =
             Encoding.ASCII.GetBytes("Lorem ipsum dolor sit amet, consectetur adipiscing elit volutpat.");
         Byte[] ciphertext = tribble.XOR(plaintext);
         tribble.Reset();
         Byte[] thereAndBackAgain = tribble.XOR(ciphertext);
         CollectionAssert.AreEqual(plaintext, thereAndBackAgain);
     }
 }
Example #6
0
 public void XOR_UCS2Test()
 {
     using (var tribble = new Tribble <SHA512>(Sample512BitKey, SHA512.Create()))
     {
         Byte[] plaintext =
             Encoding.Unicode.GetBytes("Lǫr̨e͟m̛ i̡psu̶m͡ do̵lor̛ sít ͟a̧me̛t͜,͡ ̢conseçte͞tu͞r͝ ͜a͝di͞p͢i̕s̀ci̕n͟g͏ ̴e͏lit ̧posuer̀e͢.");
         Byte[] ciphertext = tribble.XOR(plaintext);
         tribble.Reset();
         Byte[] thereAndBackAgain = tribble.XOR(ciphertext);
         CollectionAssert.AreEqual(plaintext, thereAndBackAgain);
     }
 }
Example #7
0
 public void XOR_ManyIterations()
 {
     using (var tribble = new Tribble <SHA512>(Sample512BitKey, SHA512.Create()))
     {
         Byte[] plaintext  = Encoding.ASCII.GetBytes("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ut nibh velit. Proin sagittis consequat elementum. Cras aliquet sed.");
         var    ciphertext = new List <Byte>();
         for (var i = 0; i < plaintext.Length; i++)
         {
             ciphertext.Add(tribble.XOR(plaintext.Skip(i).Take(1).ToArray())[0]);
         }
         tribble.Reset();
         var thereAndBackAgain = new List <Byte>();
         for (var i = 0; i < plaintext.Length; i++)
         {
             thereAndBackAgain.Add(tribble.XOR(ciphertext.Skip(i).Take(1).ToArray())[0]);
         }
         CollectionAssert.AreEqual(plaintext, thereAndBackAgain.ToArray());
     }
 }