Code example for KeyGenerator

Methods: generateKeyinit

0
    } 
 
    private static void test(KeyGenerator kg, int major, int minor)
            throws Exception { 
 
        kg.init(new TlsRsaPremasterSecretParameterSpec(major, minor));
        SecretKey key = kg.generateKey();
        byte[] encoded = key.getEncoded();
        if (encoded.length != 48) {
            throw new Exception("length: " + encoded.length);
        } 
        if ((encoded[0] != major) || (encoded[1] != minor)) {
            throw new Exception("version mismatch: "  + encoded[0] +
                "." + encoded[1]);
        } 
        System.out.println("OK: " + major + "." + minor);
    } 
}