Code example for X509EncodedKeySpec

0
            // Verify signature 
            if (sig != null && pub != null) {
                try { 
                    byte[] sigRaw = Base64.decode(sig, Base64.DEFAULT);
                    byte[] pubRaw = Base64.decode(stripKey(pub), Base64.DEFAULT);
                    X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(pubRaw);
                    KeyFactory kf = KeyFactory.getInstance("RSA", "BC");
                    Signature s = Signature.getInstance("SHA1withRSA", "BC");
                    s.initVerify(kf.generatePublic(publicKeySpec));
                    s.update(encRaw);
                    ver = s.verify(sigRaw);
                } catch (Exception ex) {
                    Log.i("whistle", "Verification failed: "+ex.getMessage());
                    ver = false;
                } 
            } 
             
            // Split enc into encrypted aes data and remaining enc 
            byte[] encSplit = encRaw;
            byte[] aesRaw = new byte[RSA_BYTES];
            System.arraycopy(encSplit, 0, aesRaw, 0, aesRaw.length);