Android creates a Digital Signature Application

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.