Léo Trinquet
Léo Trinquet

Reputation: 11

I can't get the SHA-1 footprint of my .NET MAUI Application

I want to publish my .NET MAUI application on the Play Store. To do this, I need to obtain the SHA-1 certificate fingerprint in order to create the OAuth client ID. I am using Visual Studio 2022.

When I try to access the key in the command prompt, it either says "invalid keystore format" or gives me a 32-byte SHA-1, which is too long (it should be 20 bytes).

I tried 3 different methods:

1. When I build my application and try to retrieve the key with this command:

keytool -list -v -keystore "C:\Users\[NAME]\AppData\Local\Xamarin\Mono for Android\debug.keystore"

It asks me to enter the password, which is "android."

I press enter and then get this error:

keytool error: java.io.IOException: Invalid keystore format
java.io.IOException: Invalid keystore format
        at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:666)
        at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:57)
        at sun.security.provider.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:224)
        at sun.security.provider.JavaKeyStore$DualFormatJKS.engineLoad(JavaKeyStore.java:71)
        at java.security.KeyStore.load(KeyStore.java:1445)
        at sun.security.tools.keytool.Main.doCommands(Main.java:935)
        at sun.security.tools.keytool.Main.run(Main.java:375)
        at sun.security.tools.keytool.Main.main(Main.java:368)

The same thing happens when I use this command:

keytool -list -v -keystore "C:\Users\[NAME]\AppData\Local\Xamarin\Mono for Android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

I should mention that the debug.keystore file is indeed located there, and I’ve tried multiple times to delete it and rebuild my application, which recreates it. But I always get the same error. Note that I get the same error whether the password is correct or not.

2. When I create my own keystore with Visual Studio’s tool and try to retrieve the key using this command:

keytool -list -v -keystore "C:\Users\[NAME]\AppData\Local\Xamarin\Mono for Android\Keystore\[ALIAS]\[ALIAS].keystore"

It asks me to enter the password I chose when creating my own keystore with Visual Studio.

Then I get the same error:

keytool error: java.io.IOException: Invalid keystore format
java.io.IOException: Invalid keystore format
        at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:666)
        at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:57)
        at sun.security.provider.KeyStoreDelegator.engineLoad(KeyStoreDelegator.java:224)
        at sun.security.provider.JavaKeyStore$DualFormatJKS.engineLoad(JavaKeyStore.java:71)
        at java.security.KeyStore.load(KeyStore.java:1445)
        at sun.security.tools.keytool.Main.doCommands(Main.java:935)
        at sun.security.tools.keytool.Main.run(Main.java:375)
        at sun.security.tools.keytool.Main.main(Main.java:368)

3. When I try to manually create my keystore in the command prompt with this command:

keytool -genkey -v -keystore "C:\Users\[NAME]\Desktop\new_keystore.keystore" -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

I can add my information and choose a password, and the keystore is successfully generated on my desktop. When I try to access it with this command:

keytool -list -v -keystore "C:\Users\[NAME]\Desktop\new_keystore.keystore"

It asks me to enter the password.

I press enter and finally get the information. But the SHA-1 fingerprint is way too long for my OAuth client ID. It has 32 bytes instead of 20:

Certificate fingerprints:
         MD5 : 0A:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:7F
         SHA1 : CC:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:1D
         SHA256 : SXXXXXXXXXXXA
Signature algorithm name: 2048-bit RSA key
Subject Public Key Algorithm: 3
Version: {10}

Upvotes: 1

Views: 364

Answers (1)

PT2550
PT2550

Reputation: 156

I ran into the same error when trying to find the fingerprint. It turned out I was using a different version of the JDK. I found the version of the JDK used by Visual Studio in Visual Studio Tools -> Xamarin -> Android Settings. When I used the keytool command from that JDK, it worked.

The command I used was:

keytool -list -v -keystore "C:\Users\[NAME]\AppData\Local\Xamarin\Mono for Android\Keystore\[KEYNAME]\[KEYNAME].keystore" -alias [KEYNAME]

Upvotes: 0

Related Questions