sensorhub-cloud-iot
sensorhub-cloud-iot copied to clipboard
Create PEM for Android Things: Invalid authentication key. Check the format.
Finally, fixed this issue by almost one day:
Firstly, execute the follow command to create a pem file, I use EC
in this command:
adb shell am start -e project_id <PROJECT_ID> -e cloud_region <REGION> -e registry_id <REGISTRY_ID> -e device_id <DEVICE_ID> [-e key_algorithm <one of RSA,EC>] com.example.androidthings.sensorhub/.SensorHubActivity
the key point is -e key_algorithm
, which allows RSA
and EC
, and EC
is actually ES256
:
ES256 key pair using the Eliptic Curve algorithm See Google Cloud Internet of Things Core - Creating Public/Private Key Pairs
Lastly, upload the pem to GCP console, and select ES256_X509
:
This function in AuthKeyGenerator.class
is actually for _X509
public void initialize() throws GeneralSecurityException, IOException {
if (certificate instanceof X509Certificate) { // is true
private void writeCertificatePEM(OutputStream os) throws GeneralSecurityException, IOException {
os.write("-----BEGIN CERTIFICATE-----\n".getBytes());
os.write(Base64.encode(certificate.getEncoded(), Base64.DEFAULT));
os.write("-----END CERTIFICATE-----\n".getBytes());
}