cryptoapi

How to import private key in PEM format using WinCrypt and C++?

拜拜、爱过 提交于 2019-11-30 22:14:09
I'm trying to use the WinCrypt API in C++. My application need to cipher, decipher, sign and verify files, and I know how to do that once I have the correct keys. But my problem is actually that that is NOT the same application which generates those keys. What I have is public and private keys in files in PEM format : -----BEGIN RSA PRIVATE KEY----- [Base64 encoded] -----END RSA PRIVATE KEY----- And : -----BEGIN RSA PUBLIC KEY----- [Base64 encoded] -----END RSA PUBLIC KEY----- After some research, I have found how to import the public key : here and here , using the following methods :

Restore RSA private key by modulus, public and private exponents using Java Security

泄露秘密 提交于 2019-11-30 19:47:59
问题 I'm trying to find Java (native or BouncyCastle provider) implementation for generating a RSA private key in PKCS#1 using given params {e,n,d}. There is paper by Dan Boneh that describes an algorithm for doing so. The solution is available in PyCrypto (Python), as well as there is a standalone utility posted by Mounir IDRASSI that converts RSA keys between the SFM format (n,e,d) and CRT format (p,q,dp,dq,u), and the other way around. However I was not able to find anything ready to use for

Saving/Restoring certs with MS CryptoAPI invalidates attached private key

天涯浪子 提交于 2019-11-30 17:04:23
I've written a program which is supposed to save and restore a users certificates using the windows Crypto API. I was under the impression that it was working fine but now a user has complained that the private key that was attached to the certificate is invalid after the cert has been restored. I was saving the certificates using: HCERTSTORE hCertStore = CertOpenStore(CERT_STORE_PROV_PHYSICAL_W, 0, NULL, CERT_SYSTEM_STORE_CURRENT_USER | CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG | CERT_STORE_UPDATE_KEYID_FLAG, (PVOID) storeName.c_str()); And then later: if (!CertSaveStore

Digital Signature SunMSCAPI provider & MS Crypto API

只愿长相守 提交于 2019-11-30 08:48:11
问题 I want to sign file with the SunMSCAPI provider. As public key and signatures needs to be imported using MS Crypto API. Generally generating signatures with SHA1withRSA , ends up with big-endian to little-endian (byte order) conversion. //generate keystore with java keytool $Keytool -genkey -alias tsign -keystore c:\test\tsignjks.p12 - keyalg rsa -storetype pkcs12 In Java application: //for signing and getting keystore, assuming windows certificate is installed ..ks = KeyStore.getInstance(

Java File Encryption

房东的猫 提交于 2019-11-30 07:55:04
问题 I'm trying to write a simple program to encrypt and decrypt files using the AES algortihm. I haven't problems with encryption, but decryption.. public static void main(String[] args) throws NoSuchAlgorithmException, FileNotFoundException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { // Инициализация секретных ключей KeyGenerator keyGenS = KeyGenerator.getInstance("AES"); keyGenS.init(128); SecretKey sKey1 = keyGenS.generateKey(); SecretKey

MS Crypto API behavior on Windows XP vs Vista/7

左心房为你撑大大i 提交于 2019-11-30 03:50:09
问题 I'm trying to understand how to get a public key imported from PEM format (sample included in the code below) across XP, Vista and Windows 7. The sample code will import the key on both XP and Windows Vista/7, but not the same way. On Windows XP, the string "(Prototype)" is required in the cryptographic provider's name, and allows the call to CryptImportPublicKeyInfo to pass. On Windows 7, the "(Prototype)" provider is apparently present, but does not support the call to

MD5-SHA1 hash using CryptoAPI

不想你离开。 提交于 2019-11-29 17:38:12
I have requirement of signing a data using MD5-SHA1 hash (MD5 hash and SHA1 hash of the data are combined and then signed). Primary requirement: MD5-SHA1 hash is provided by OpenSSL in some way that is not exposed. This hash is complete. Now my requirement is to sign this hash using Crypto API without hashing (only signing is required, not hashing again). Why CryptoAPI, not OpenSSL? Because, I am dealing with a certificate with non-exportable private key. Its private key can only be used by CryptoAPI, not by OpenSSL. This scenario is from SSL handshake where send Client verify part (under the

Digital Signature SunMSCAPI provider & MS Crypto API

我只是一个虾纸丫 提交于 2019-11-29 08:05:38
I want to sign file with the SunMSCAPI provider. As public key and signatures needs to be imported using MS Crypto API. Generally generating signatures with SHA1withRSA , ends up with big-endian to little-endian (byte order) conversion. //generate keystore with java keytool $Keytool -genkey -alias tsign -keystore c:\test\tsignjks.p12 - keyalg rsa -storetype pkcs12 In Java application: //for signing and getting keystore, assuming windows certificate is installed ..ks = KeyStore.getInstance("Windows-MY","SunMSCAPI"); PrivateKey priv = ks.getKey("tsign",password); Signature rsa = Signature

Java security - MSCAPI provider: How to use without password popup?

喜夏-厌秋 提交于 2019-11-29 07:11:14
I've managed to use Sun's MSCAPI provider in my application. The problem I'm having now is that it always pops up a window, asking for a password, even though I've provided it in the code. This is a problem, because I need the cryptography functionality in a webservice. Here's the code I have now: String alias = "Alias to my PK"; char[] pass = "MyPassword".toCharArray(); KeyStore ks = KeyStore.getInstance("Windows-MY"); ks.load(null, pass); Provider p = ks.getProvider(); Signature sig = Signature.getInstance("SHA1withRSA",p); PrivateKey key = (PrivateKey) ks.getKey(alias, pass) sig.initSign

Java File Encryption

你。 提交于 2019-11-29 05:17:43
I'm trying to write a simple program to encrypt and decrypt files using the AES algortihm. I haven't problems with encryption, but decryption.. public static void main(String[] args) throws NoSuchAlgorithmException, FileNotFoundException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { // Инициализация секретных ключей KeyGenerator keyGenS = KeyGenerator.getInstance("AES"); keyGenS.init(128); SecretKey sKey1 = keyGenS.generateKey(); SecretKey sKey2 = keyGenS.generateKey(); // Перевод секретных ключей в строку и запись в файл String key1 =