AWS Android SDK IoT - PKCS8 key reading not supported?

24 Views Asked by At

I'm working on an Android project that uses the AWS Android SDK IoT.

I have a weird issue reading a .key file with this library. The .key has been generated with the PKCS8 encoding (not with PKCS1).

If a look at the library source code on GitHub (https://github.com/aws-amplify/aws-sdk-android/blob/main/aws-android-sdk-iot/src/main/java/com/amazonaws/mobileconnectors/iot/PEM.java), in the comments I read that PKCS8 is supported:

"... With this PEM utility, private keys in either PKCS#1 or PKCS#8 PEM encoded format can be read..."

However, the source code of the readPrivateKey() method supports PKCS1 only:

public static PrivateKey readPrivateKey(InputStream is)
            throws InvalidKeySpecException, IOException {
        List<PEMObject> objects = readPEMObjects(is);
        for (PEMObject object : objects) {
            switch (object.getPEMObjectType()) {

               case PRIVATE_KEY_PKCS1:
                    return RSA.privateKeyFromPKCS1(object.getDerBytes());
                default:
                    break;

            }
        }
        throw new IllegalArgumentException("Found no private key");
    }

So, when I run my application, an error arises from the code above (the "Found no private key" exception). Is it normal? Does anyone know something about this topic?

What I'm expecting: to be able to process .key files in PKCS8 format.

0

There are 0 best solutions below