How to specify a cipher for an SSL connection in .NET?
How can I specify a cipher suite to use in an SSL Connections?
I know that Mentalis Seclib got this feature however they don't maintain the project (and there are issues in that library with x开发者_JAVA技巧64 OSes) as they say .NET Framework 2.0 introduced those features, however I couldn't find a way to do this in .NET Framework 3.5.
To be more specific I want to connect an HTTPS service by using NULL cipher, I would do the same thing with OpenSSL by using the following command:
openssl s_client -connect www.example.com:443 -cipher NULL
How can I do this in .NET?
Also commercial or commercial friendly licensed library suggestions are welcome as well.
(My previous answer was ill-informed, I did not notice at first that the property I was referring to was read-only.)
In .NET 4, the System.Net.Security.SslStream
class supports a new constructor, allowing you to provide an EncryptionPolicy
value, which could be NoEncryption
. This allows no encryption and request that a NULL cipher be used if the other endpoint can handle a NULL cipher.
Unfortunately this did not exist even in 3.5.
Not really part of the question, but I assume (and this is really for future readers) that you are of course aware of the relevant risks, of using SSL with a NULL cipher? And, the benefits you miss out on?
Based on the documentation, you can set the ciphers when using SChannel via the palgSupportedAlgs, dwMinimumCipherStrength, and dwMaximumCipherStrength parameters of the SCHANNEL_CRED struct.
In order to enable the NULL encryption algorithm, you should set dwMinimumCipherStrength to -1.
CAVEAT: This is based on the documentation only. I am not a .NET developer, but I have been looking for an answer to the question because I support a service that has .NET clients.
In .NET, you can use the SSLStream class. in .NET 4.0, as Matthieu says above, it allows you to specify the ciphers.
精彩评论