Android Open Source
Open Source Java App RSA Crypto In the previous post, there was a joke about the fact that encryption keys in PCA cannot be written to a file, sent, or converted. For those whose nerves are well tuned, let's continue. Encryption keys can be saved to a file and restored from a file. Although this is not the most secure way to store them. byte [] pubKeyBytes = new byte[pubKeyLength]; FileInputStream privIn = new FileInputStream (privateKey); FileInputStream pubIn = new FileInputStream (publicKey); privIn. read (privKeyBytes); pubIn. read (pubKeyBytes); pubIn. close (); KeyFactory keyFactory = KeyFactory. getInstance ( "RSA" ); EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec (privKeyBytes); EncodedKeySpec publicKeySpec = new X509EncodedKeySpec (pubKeyBytes); crypto.keyPair = new KeyPair(keyFactory. generatePublic (publicKeySpec), keyFactory. generatePrivate (privateKeySpec)); crypto.base64 = base64; That's enough to get it all done. Of course, t...