public static ApnsSigningKey loadFromInputStream ( final InputStream inputStream , final String teamId , final String keyId ) throws IOException , NoSuchAlgorithmException , InvalidKeyException { final ECPrivateKey signingKey ; { final String base64EncodedPrivateKey ; { final StringBuilder privateKeyBuilder = new StringBuilder ( ) ; final BufferedReader reader = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; boolean haveReadHeader = false ; boolean haveReadFooter = false ; for ( String line ; ( line = reader . readLine ( ) ) != null ; ) { if ( ! haveReadHeader ) { if ( line . contains ( "BEGIN PRIVATE KEY" ) ) { haveReadHeader = true ; } } else { if ( line . contains ( "END PRIVATE KEY" ) ) { haveReadFooter = true ; break ; } else { privateKeyBuilder . append ( line ) ; } } } if ( ! ( haveReadHeader && haveReadFooter ) ) { throw new IOException ( "Could not find private key header/footer" ) ; } base64EncodedPrivateKey = privateKeyBuilder . toString ( ) ; } final byte [ ] keyBytes = decodeBase64EncodedString ( base64EncodedPrivateKey ) ; final PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec ( keyBytes ) ; final KeyFactory keyFactory = KeyFactory . getInstance ( "EC" ) ; try { signingKey = ( ECPrivateKey ) keyFactory . generatePrivate ( keySpec ) ; } catch ( InvalidKeySpecException e ) { throw new InvalidKeyException ( e ) ; } } return new ApnsSigningKey ( keyId , teamId , signingKey ) ; }
Loads a signing key from the given input stream .