public void TestDecrypt(string signed) { string subDir = "bson_session"; if (!string.IsNullOrWhiteSpace(signed)) { subDir = "signed_" + subDir; } else { publicKeyVerifier = publicKeyVerifier.SafeDispose(); } var subPath = Util.TestDataPath(TEST_DATA, subDir, "unofficial"); var sessionMaterialInput = (WebBase64)File.ReadAllLines(Path.Combine(subPath, "session.out")).First(); var sessionCiphertextInput = (WebBase64)File.ReadAllLines(Path.Combine(subPath, "ciphertext.out")).First(); using ( var sessionCrypter = new SessionCrypter(privateKeyDecrypter, sessionMaterialInput, publicKeyVerifier, new BsonSessionKeyPacker())) { var plaintext = sessionCrypter.Decrypt(sessionCiphertextInput); Expect(plaintext, Is.EqualTo(input)); } }
public void TestCreateSessions(string topDir, string subDir, string signed, string packer, string sessionFilename, string ciphertextFilename) { var kspath = Util.TestDataPath(WRITE_DATA, topDir, subDir); Directory.CreateDirectory(kspath); ISessionKeyPacker keyPacker = null; int? keySize = null; KeyType keyType = null; if (!String.IsNullOrWhiteSpace(packer)) { keyPacker = new BsonSessionKeyPacker(); keySize = 256; keyType = UnofficialKeyType.AesAead; } using (var encrypter = new Encrypter(Util.TestDataPath(WRITE_DATA, "rsa.public"))) using (var signer = String.IsNullOrWhiteSpace(signed) ? null : new AttachedSigner(Util.TestDataPath(WRITE_DATA, "dsa"))) using (var session = new SessionCrypter(encrypter, signer, keySize, keyType, keyPacker)) { var material = session.SessionMaterial; var ciphertext = session.Encrypt(input); File.WriteAllText(Path.Combine(kspath, sessionFilename), material); File.WriteAllText(Path.Combine(kspath, ciphertextFilename), ciphertext); } }
public void Write(byte[] keyData, int version) { using (var sessionCrypter = new SessionCrypter(_encrypter, keySize: 256, symmetricKeyType: UnofficialKeyType.AesAead, keyPacker: _sessionPacker)) { var sessionMaterial = sessionCrypter.SessionMaterial; var cipherData = sessionCrypter.Encrypt(keyData); var session = new CertEncryptedKeySet.SessionPack(sessionMaterial, cipherData); var json = Keyczar.Util.Utility.ToJson(session); var jsonData = this.GetConfig().RawStringEncoding.GetBytes(json); _writer.Write(jsonData, version); } }
public byte[] GetKeyData(int version) { var data = _keySet.GetKeyData(version); var jsonString = this.GetConfig().RawStringEncoding.GetString(data); var pack = JsonConvert.DeserializeObject <SessionPack>(jsonString); using (var sessionCrypter = new SessionCrypter(_crypter, pack.SessionMaterial, keyPacker: _sessionPacker)) { return(sessionCrypter.Decrypt(pack.CipherText)); } }
public void DecryptSession() { var path = TestData(Location); var material = (WebBase64)File.ReadAllLines(Path.Combine(path, "2.session.material")).First(); var ciphertext = (WebBase64)File.ReadAllLines(Path.Combine(path, "2.session.ciphertext")).First(); using (var crypter = new Crypter(path)) using (var sessionCrypter = new SessionCrypter(crypter, material)) { var decrypted = sessionCrypter.Decrypt(ciphertext); Expect(decrypted, Is.EqualTo(Input)); } }
public void DecryptSession() { var path = TestData(Location); var material = (WebBase64) File.ReadAllLines(Path.Combine(path, "2.session.material")).First(); var ciphertext = (WebBase64) File.ReadAllLines(Path.Combine(path, "2.session.ciphertext")).First(); using (var crypter = new Crypter(path)) using (var sessionCrypter = new SessionCrypter(crypter, material)) { var decrypted = sessionCrypter.Decrypt(ciphertext); Expect(decrypted, Is.EqualTo(Input)); } }
public void TestDecrypt() { var subPath = Util.TestDataPath(TEST_DATA, "rsa"); var sessionMaterialInput = (WebBase64) File.ReadAllLines(Path.Combine(subPath, "session.material.out")).First(); var sessionCiphertextInput = (WebBase64) File.ReadAllLines(Path.Combine(subPath, "session.ciphertext.out")).First(); using (var sessionCrypter = new SessionCrypter(privateKeyDecrypter, sessionMaterialInput)) { var plaintext = sessionCrypter.Decrypt(sessionCiphertextInput); Expect(plaintext, Is.EqualTo(input)); } }
public void TestDecrypt() { var subPath = Util.TestDataPath(TEST_DATA, "rsa"); var sessionMaterialInput = (WebBase64)File.ReadAllLines(Path.Combine(subPath, "session.material.out")).First(); var sessionCiphertextInput = (WebBase64)File.ReadAllLines(Path.Combine(subPath, "session.ciphertext.out")).First(); using (var sessionCrypter = new SessionCrypter(privateKeyDecrypter, sessionMaterialInput)) { var plaintext = sessionCrypter.Decrypt(sessionCiphertextInput); Expect(plaintext, Is.EqualTo(input)); } }
public static string[] Encrypter(string textToEncrypt, PathProvider p) { WebBase64 sessionMaterial; WebBase64 cipherText; string[] data; string path = p.GetPublicPath(); using (var encrypter = new Encrypter(path)) using (var sessionCrypter = new SessionCrypter(encrypter)) { sessionMaterial = sessionCrypter.SessionMaterial; cipherText = sessionCrypter.Encrypt(textToEncrypt); data = new string[] { sessionMaterial.ToString(), cipherText.ToString() }; //data.Add("sessionmaterial", sessionMaterial); //data.Add("data", cipherText); } return data; }
public static string Decrypt(string[] data, PathProvider p) { WebBase64 sessionMaterial = (WebBase64)data[0]; WebBase64 cipherText = (WebBase64)data[1]; string output; //PathProvider pathProvider = new PathProvider(); string path1 = p.GetPrivatePath(); //string path1 = HostingEnvironment.ApplicationPhysicalPath + "encryption"; using (var crypter = new Crypter(path1)) using (var sessionCrypter = new SessionCrypter(crypter, sessionMaterial)) { output = sessionCrypter.Decrypt(cipherText); } return output; }
public void TestDecrypt(string signed) { string subDir = "bson_session"; if (!string.IsNullOrWhiteSpace(signed)) { subDir = "signed_" + subDir; } else { publicKeyVerifier = publicKeyVerifier.SafeDispose(); } var subPath = Util.TestDataPath(TEST_DATA, subDir, "unofficial"); var sessionMaterialInput = (WebBase64) File.ReadAllLines(Path.Combine(subPath, "session.out")).First(); var sessionCiphertextInput = (WebBase64) File.ReadAllLines(Path.Combine(subPath, "ciphertext.out")).First(); using ( var sessionCrypter = new SessionCrypter(privateKeyDecrypter, sessionMaterialInput, publicKeyVerifier, new BsonSessionKeyPacker())) { var plaintext = sessionCrypter.Decrypt(sessionCiphertextInput); Expect(plaintext, Is.EqualTo(input)); } }
protected int TakeAction(IKeySet keyset, Stream inStream, Stream outStream, Stream outStream2, IKeySet keyset2) { if ((WireFormat.IsNullOrEmpty(_format) && (keyset.Metadata.Purpose == KeyPurpose.DecryptAndEncrypt || keyset.Metadata.Purpose == KeyPurpose.Encrypt)) || _format == WireFormat.Crypt ) { using (var ucrypter = new Encrypter(keyset)) { var err = UseCompression(ucrypter); if (err != 0) { return(err); } ucrypter.Encrypt(inStream, outStream); } } else if (WireFormat.IsNullOrEmpty(_format) || _format == WireFormat.Sign) { using (var signer = new Signer(keyset)) { var sig = signer.Sign(inStream); outStream.Write(sig, 0, sig.Length); } } else if (_format == WireFormat.SignTimeout) { using (var signer = new TimeoutSigner(keyset)) { var sig = signer.Sign(inStream, _expires.GetValueOrDefault()); outStream.Write(sig, 0, sig.Length); } } else if (_format == WireFormat.SignAttached) { using (var signer = new AttachedSigner(keyset)) { byte[] hidden = null; if (!String.IsNullOrWhiteSpace(_attachedHidden)) { hidden = Keyczar.Keyczar.RawStringEncoding.GetBytes(_attachedHidden); } signer.Sign(inStream, outStream, hidden); } } else if (_format == WireFormat.SignVanilla || _format == WireFormat.SignUnversioned) { using (var signer = new Keyczar.Compat.VanillaSigner(keyset)) { var sig = signer.Sign(inStream); outStream.Write(sig, 0, sig.Length); } } else if (_format == WireFormat.CryptSession) { using (var crypter = new Encrypter(keyset)) using (var sessionCrypter = new SessionCrypter(crypter)) { var err = UseCompression(sessionCrypter); if (err != 0) { return(err); } var materials = sessionCrypter.SessionMaterial.ToBytes(); outStream.Write(materials, 0, materials.Length); sessionCrypter.Encrypt(inStream, outStream2); } } else if (_format == WireFormat.CryptSignedSession) { if (keyset2 == null) { Console.WriteLine(Localized.MsgRequiresLocation2); return(-1); } using (var crypter = new Encrypter(keyset)) using (var signer = new AttachedSigner(keyset2)) using (var sessionCrypter = new SessionCrypter(crypter, signer)) { var err = UseCompression(sessionCrypter); if (err != 0) { return(err); } var materials = sessionCrypter.SessionMaterial.ToBytes(); outStream.Write(materials, 0, materials.Length); sessionCrypter.Encrypt(inStream, outStream2); } } else { Console.WriteLine(Localized.MsgUnknownFormat, _format); return(-1); } return(0); }