Solution to java.io.IOException: Invalid keystore format error encountered when Android applies for security code SHA1

Foreword:

I recently planned to do a project and needed to call some large company APIs (Amap or Baidu Map). I found that a java.io.IOException: Invalid keystore format error occurred when obtaining the security code. How to solve this error? After working on it for two hours, I found a way to solve it.

Open Android studio:

After opening android studio, click the File option in the upper right corner and select Project Structure...

After opening, click SDK Location. There is a blue option Gradle Setting below, click to open.

Click on Gradle JDK and you will find that if you have not configured JDK before and are using the version that comes with android studio, it may be different from the JDK version installed on your host.

What is JDK? JDK is the abbreviation of Java Development ToolKit, which is Java development tool kit. It contains compilers, debuggers, runtime environments, class libraries, and other utilities for developing, compiling, debugging, and running Java programs. It provides some important components, such as Java compiler (javac), Java virtual machine (JVM), and Java class library (Java Class Library). Broadly speaking,JDK is a collection of tools and resources for Java development that enables developers to write, compile, debug, and run Java programs.

Find directory

We find the default JDK storage path of android, as shown in the figure (my storage path is D:\program\android\Androidstudio\jbr\bin)

Open it with a folder, type cmd on the folder path, and press Enter to enter.

So we entered the command operation interface under the directory line. We can obtain SHA1 in this operation interface.

Get the development version SHA1 security code

We open the user (User) file on the c drive, open the file named 123456 (just a string of numbers), open the .android file, and find debug.keystore. This is the keystore. The security code can be obtained through the command. Copy the path to the keystore. (To save trouble, I can also enter the command cd through the command line)

Enter in the command line interface just now:keytool -v -list -keystore debug.keystore, the default password is android.

In this way, the SHA1 security code of the development version is obtained.

Get the release SHA1 security code

Open Android studio and operate as shown below to keep up with the rhythm.

Click OK, and then set the following. It is recommended that you write the same password for all passwords, otherwise you will not be able to tell them apart.

 

After is created, there will be a jks file in the path where we store it. A JKS file is a Java key store file used to manage and store keys, certificates, and trusted Certificate Authority (CA) root certificates in Java programs< a i=2>. In a Java program, you can use the KeyStore class to load and manipulate JKS files.

 Then we return to the command line interface just now and enter: keytool -v -list -keystore + Path + File name and suffix, that’s it.

Done, the problem is perfectly solved

Error cause analysis:

This may be caused by using a different version of the keystore format or an incompatible tool. Thekeytool tool in Java is used to handle keystores, including creating, importing, Export, view certificates and other operations. However different versions of JDK/JRE may use different default keystore formats. For example, older versions may use the JKS (Java KeyStore) format, while newer versions may prefer the PKCS12 format. There are differences in the internal structure and file encoding between the two formats.

To solve this problem, you can update the JDK version of the host so that there is a corresponding version of the keytool tool. Or just like me, use the default JDK of android, which is a version compatible with it, and you can open it.

Additional instructions:

There is more than one reason for the java.io.IOException: Invalid keystore format error encountered when Android applies for security code SHA1, and what I solved today is one of the reasons. If you haven’t successfully solved it by following my above steps, you can read articles written by other bloggers.

Guess you like

Origin blog.csdn.net/lb220303082/article/details/133242616