Dave's Brain

Browse - Programming Tips - How can I do a SSL / TLS connection in my win32 application?

Date: 2017jan26
OS: Windows
Platform: win32
Language: C/C++
Keywords: intro, introduction

Q.  How can I do a SSL / TLS connection in my win32 application?

A.  There are two ways.
Use WinInet like this:

#include "Wininet.h" HINTERNET m_hInternet = InternetOpen(szId, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); HINTERNET m_hConnection = InternetConnect( m_hInternet, szServerName, INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, dwFlags, 0);
But this only works for HTTP and FTP. Or you can use Microsoft SecureChannel. Your code will begin:
#include <winsock2.h> #include <wincrypt.h> #include <wintrust.h> #include <schannel.h> #include <security.h> #include <sspi.h> #include <deque>
This uses regular winsock2 sockets and you call some (complicated) functions to upgrade the connection to secure. So this is more low-level than the method above.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.