Load an PEM encoded X.509 certificate into Windows CryptoAPI

KJKHyperion said in his answer: I discovered the “magic” sequence of calls to import a RSA public key in PEM format. Here you go: decode the key into a binary blob with CryptStringToBinary; pass CRYPT_STRING_BASE64HEADER in dwFlags decode the binary key blob into a CERT_PUBLIC_KEY_INFO with CryptDecodeObjectEx; pass X509_ASN_ENCODING in dwCertEncodingType and X509_PUBLIC_KEY_INFO in lpszStructType … Read more

Windows C/C++ Crypto API Examples and tips

Here’s a bunch of examples I’ve found…. Example C Program: Listing the Certificates in a Store Example C Program: Using CryptAcquireContext Example C Program: Enumerating CSP Providers and Provider Types Example C Code for Opening Certificate Stores Example C Program: Sending and Receiving a Signed and Encrypted Message Example C Program: Signing a Hash and … Read more

How to generate an HMAC in Java equivalent to a Python example?

HmacSHA1 seems to be the algorithm name you need: SecretKeySpec keySpec = new SecretKeySpec( “qnscAdgRlkIhAUPY44oiexBKtQbGY0orf7OV1I50”.getBytes(), “HmacSHA1”); Mac mac = Mac.getInstance(“HmacSHA1”); mac.init(keySpec); byte[] result = mac.doFinal(“foo”.getBytes()); BASE64Encoder encoder = new BASE64Encoder(); System.out.println(encoder.encode(result)); produces: +3h2gpjf4xcynjCGU5lbdMBwGOc= Note that I’ve used sun.misc.BASE64Encoder for a quick implementation here, but you should probably use something that doesn’t depend on the Sun … Read more