package Ġio . github . w ulkan owy . signer . he be . android Ċ Ċ import Ġandroid . content . Context Ċ import Ġandroidx . test . core . app . Application Provider Ċ import Ġandroidx . test . ext . junit . runners . Android JUnit 4 Ċ import Ġcom . mig components . mig base 6 4 . Base 6 4 Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġjava . io . ByteArray InputStream Ċ import Ġjava . math . BigInteger Ċ import Ġjava . security . Key Factory Ċ import Ġjava . security . Message Digest Ċ import Ġjava . security . cert . Certificate Factory Ċ import Ġjava . security . interfaces . RSA Key Ċ import Ġjava . security . spec . PKCS 8 Encoded KeySpec Ċ import Ġjava . security . spec . RS AP rivate KeySpec Ċ import Ġjava . security . spec . RS AP ublic KeySpec Ċ Ċ @ RunWith ( Android JUnit 4 :: class ) Ċ class ĠGenerator Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġcontext Ġ= ĠApplication Provider . getApplicationContext < Context >() ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġgenerator Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġ( certificate , Ġfingerprint , ĠprivateKey ) Ġ= Ġgenerate KeyPair ( context , Ġ" Key Entry ") ĊĊĠĠĠĠĠĠĠ Ġval Ġcertificate Factory Ġ= ĠCertificate Factory . getInstance (" X . 5 0 9 ") ĊĠĠĠĠĠĠĠ Ġval Ġx 5 0 9 Ġ= Ġcertificate Factory . generate Certificate ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠByteArrayInputStream ( Base 6 4 . decode Fast ( certificate )) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġkey Factory Ġ= ĠKey Factory . getInstance (" RSA ") ĊĠĠĠĠĠĠĠ Ġval ĠpublicKey Spec Ġ= ĠRS AP ublic KeySpec (( privateKey Ġas ĠRSA Key ). modulus , ĠBigInteger . valueOf ( 6 5 5 3 7 )) ĊĠĠĠĠĠĠĠ Ġval ĠpublicKey Ġ= Ġkey Factory . generate Public ( publicKey Spec ) ĊĊĠĠĠĠĠĠĠ Ġval Ġdigest Ġ= ĠMessage Digest . getInstance (" SHA - 1 ") ĊĠĠĠĠĠĠĠ Ġdigest . update ( x 5 0 9 . encoded ) ĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( fingerprint . length , Ġ 4 0 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( digest . digest (). join ToString ("") Ġ{ Ġ"% 0 2 x ". format ( it ) Ġ}, Ġfingerprint ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( x 5 0 9 . publicKey , ĠpublicKey ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġgetter Test () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġ( certificate 1 , Ġfingerprint 1 , ĠprivateKey 1 ) Ġ= Ġgenerate KeyPair ( context , Ġ" Key Entry ") ĊĠĠĠĠĠĠĠ Ġval Ġ( certificate 2 , Ġfingerprint 2 , ĠprivateKey 2 ) Ġ= ĠgetKey Entry (" Key Entry ") !! ĊĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( certificate 1 , Ġcertificate 2 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( fingerprint 1 , Ġfingerprint 2 ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( privateKey 1 , ĠprivateKey 2 ) ĊĠĠĠ Ġ} Ċ } Ċ