Some people say that android only supports BKS certificates. I do not know whether it is true or false, so I first created a BKS certificate.
Steps:
1. Download The bcprov-jdk16-141.jar and put it in the \ jre \ lib \ ext directory
2. Modify the jre6 \ lib \ security \ java. security File and add security. provider.10 = org. bouncycastle. jce. provider. BouncyCastleProvider to the file.
Find the security. provider in this file, followed by the serial number, and the local machine is incremented to 10
3. Create a keystore. Command:
Keytool-genkey-alias <alias>-keypass <key password>-keyalg Test-keysize 1024-validity 365-keystore <library file name, such as runcerts. keystore>-storepass <certificate Database Password>-dname "cn = testUsr, ou = product department, o = XXX company, c = CN, S = shandong"-storetype BKS-provider org. bouncycastle. jce. provider. bouncyCastleProvider
4. Signature and Verification
// Read the keystore:
FileInputStream is = new FileInputStream ("C: \ Inetpub \ runcerts. keystore ");
KeyStore ks = KeyStore. getInstance ("BKS", "BC ");
Ks. load (is, "123456". toCharArray ());
Is. close ();
// Read the Private Key
PrivateKey priKey1 = (PrivateKey) ks. getKey ("test2", "123456". toCharArray ());
PrivateKeyString = getKeyString (priKey1 );
// Signature
SignText = DataSign (plainText, privateKeyString );
// Verify the following
// Obtain the certificate
Certificate certificate = ks. getCertificate ("test2 ");
// Obtain the certificate
PublicKey publicKey1 = certificate. getPublicKey ();
PublicKeyString = getKeyString (publicKey1 );
// Verify
Byte [] plainText1 = "Happy New Year !! Email: @ qq.com ". getBytes ();
Boolean verySign = verify (plainText1, publicKeyString, SignText );
String s2 = new Boolean (verySign). toString ();
System. out. print ("Verification Result:" + s2 + "/n ");
Note: This step is generally used. The Code details are not pasted.