Code example for X509EncodedKeySpec

Methods: getEncoded

        // Reference array 
        byte[] encodedKey = new byte[] {(byte)1,(byte)2,(byte)3,(byte)4};
        // Reference array's copy will be used for test 
        byte[] encodedKeyCopy = encodedKey.clone();
        X509EncodedKeySpec meks = new X509EncodedKeySpec(encodedKeyCopy);
        byte[] ek = meks.getEncoded();        
        // Modify returned array 
        ek[3] = (byte)5;
        // Get encoded key again 
        byte[] ek1 = meks.getEncoded();
        // Check using reference array that 
        // byte value has not been changed 
        assertTrue(Arrays.equals(encodedKey, ek1));
Connect your IDE to all the code out there  Get Codota for Java