发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
com.lc.lcmetting.basic.utilsjava.io.BufferedReaderjava.io.IOExceptionjava.io.InputStreamjava.io.InputStreamReaderjava.math.BigIntegerjava.security.KeyFactoryjava.security.KeyPairjava.security.KeyPairGeneratorjava.security.NoSuchAlgorithmExceptionjava.security.PrivateKeyjava.security.PublicKeyjava.security.interfaces.RSAPrivateKeyjava.security.interfaces.RSAPublicKeyjava.security.spec.InvalidKeySpecExceptionjava.security.spec.PKCS8EncodedKeySpecjava.security.spec.RSAPublicKeySpecjava.security.spec.X509EncodedKeySpecjavax.crypto.Cipherandroid.R.attr.LcRSAUtils { String = String = + + + + + + + [] ([] data) { { PublicKey publicKey = ()Cipher cipher = Cipher.()cipher.init(Cipher.publicKey)cipher.doFinal(data)} (Exception e) { e.printStackTrace()} } KeyPair () { ()} KeyPair (keyLength) { { KeyPairGenerator kpg = KeyPairGenerator.()kpg.initialize(keyLength)kpg.genKeyPair()} (NoSuchAlgorithmException e) { e.printStackTrace()} } [] ([] dataPublicKey publicKey) { { Cipher cipher = Cipher.()cipher.init(Cipher.publicKey)cipher.doFinal(data)} (Exception e) { e.printStackTrace()} } [] ([] encryptedDataPrivateKey privateKey) { { Cipher cipher = Cipher.()cipher.init(Cipher.privateKey)cipher.doFinal(encryptedData)} (Exception e) { } } PublicKey ([] keyBytes) NoSuchAlgorithmExceptionInvalidKeySpecException { X509EncodedKeySpec keySpec = X509EncodedKeySpec(keyBytes)KeyFactory keyFactory = KeyFactory.()PublicKey publicKey = keyFactory.generatePublic(keySpec)publicKey} PrivateKey ([] keyBytes) NoSuchAlgorithmExceptionInvalidKeySpecException { PKCS8EncodedKeySpec keySpec = PKCS8EncodedKeySpec(keyBytes)KeyFactory keyFactory = KeyFactory.()PrivateKey privateKey = keyFactory.generatePrivate(keySpec)privateKey} PublicKey (String modulusString publicExponent) NoSuchAlgorithmExceptionInvalidKeySpecException { BigInteger bigIntModulus = BigInteger(modulus)BigInteger bigIntPrivateExponent = BigInteger(publicExponent)RSAPublicKeySpec keySpec = RSAPublicKeySpec(bigIntModulusbigIntPrivateExponent)KeyFactory keyFactory = KeyFactory.()PublicKey publicKey = keyFactory.generatePublic(keySpec)publicKey} PrivateKey (String modulusString privateExponent) NoSuchAlgorithmExceptionInvalidKeySpecException { BigInteger bigIntModulus = BigInteger(modulus)BigInteger bigIntPrivateExponent = BigInteger(privateExponent)RSAPublicKeySpec keySpec = RSAPublicKeySpec(bigIntModulusbigIntPrivateExponent)KeyFactory keyFactory = KeyFactory.()PrivateKey privateKey = keyFactory.generatePrivate(keySpec)privateKey} PublicKey (String publicKeyStr) Exception { { [] buffer = Base64Utils.(publicKeyStr)KeyFactory keyFactory = KeyFactory.()X509EncodedKeySpec keySpec = X509EncodedKeySpec(buffer)(RSAPublicKey) keyFactory.generatePublic(keySpec)} (NoSuchAlgorithmException e) { Exception()} (InvalidKeySpecException e) { Exception()} (NullPointerException e) { Exception()} } PrivateKey (String privateKeyStr) Exception { { [] buffer = Base64Utils.(privateKeyStr)PKCS8EncodedKeySpec keySpec = PKCS8EncodedKeySpec(buffer)KeyFactory keyFactory = KeyFactory.()(RSAPrivateKey) keyFactory.generatePrivate(keySpec)} (NoSuchAlgorithmException e) { Exception()} (InvalidKeySpecException e) { Exception()} (NullPointerException e) { Exception()} } PublicKey (InputStream in) Exception { { ((in))} (IOException e) { Exception()} (NullPointerException e) { Exception()} } PrivateKey (InputStream in) Exception { { ((in))} (IOException e) { Exception()} (NullPointerException e) { Exception()} } String (InputStream in) IOException { BufferedReader br = BufferedReader(InputStreamReader(in))String readLine = StringBuilder sb = StringBuilder()((readLine = br.readLine()) != ) { (readLine.charAt() == ) { } { sb.append(readLine)sb.append()} } sb.toString()} (PublicKey publicKey) { RSAPublicKey rsaPublicKey = (RSAPublicKey) publicKeySystem..println()System..println(+ rsaPublicKey.getModulus().bitLength())System..println(+ rsaPublicKey.getModulus().toString())System..println(+ rsaPublicKey.getPublicExponent().bitLength())System..println(+ rsaPublicKey.getPublicExponent().toString())} (PrivateKey privateKey) { RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) privateKeySystem..println()System..println(+ rsaPrivateKey.getModulus().bitLength())System..println(+ rsaPrivateKey.getModulus().toString())System..println(+ rsaPrivateKey.getPrivateExponent().bitLength())System..println(+ rsaPrivateKey.getPrivateExponent().toString())} }
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。