sslcrypto icon indicating copy to clipboard operation
sslcrypto copied to clipboard

OpenSSL Generated Keys?

Open CaffeineLab opened this issue 4 years ago • 4 comments
trafficstars

We created a key as:

openssl ecparam -name prime256v1 -genkey -noout -out private-key.pem

But whenever trying to decrypt we get an error for wrong curve.

curve = sslcrypto.ecc.get_curve("prime256v1") print(curve.decrypt(ciphertext, private_key, algo="aes-256-ofb") )

Not sure if I'm far off or close enough - but any direction will be appreciated.

CaffeineLab avatar Sep 03 '21 18:09 CaffeineLab

Perhaps the problem is in the ciphertext format. sslcrypto expects the ciphertext to start with 16 bits of AES IV, followed by the ephemeral public key, followed by the AES-encrypted data.

It'd be great if you specified which library you're using to encrypt the data and how you're using it.

purplesyringa avatar Sep 03 '21 20:09 purplesyringa

The app sending me the encrypted message is JAVA - here's the encryption snippet:

        byte[] plainTextBytes = inputData.getBytes("UTF-8");
        cipher = Cipher.getInstance("ECIES", BouncyCastleProvider.PROVIDER_NAME);
        cipher.init(Cipher.ENCRYPT_MODE, keys.getPublic());
        byte[] encryptedData = cipher.doFinal(plainTextBytes);
        return Base64.getEncoder().encodeToString(encryptedData);

CaffeineLab avatar Sep 03 '21 21:09 CaffeineLab

It'd help if you sent me an example of a ciphertext (here or to [email protected]). I can only guess the format is probably PKCS #7, but I'd like to make sure.

purplesyringa avatar Sep 04 '21 16:09 purplesyringa

Sent.

CaffeineLab avatar Sep 13 '21 18:09 CaffeineLab