Code example for PKCS8EncodedKeySpec

Methods: getEncoded

0
        // 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();
         
        PKCS8EncodedKeySpec meks = new PKCS8EncodedKeySpec(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));
    } 
 
Stop searching for code, let great code find you!  Add Codota to your java IDE