protected Object readResolve ( ) throws ObjectStreamException { try { if ( type == Type . SECRET && RAW . equals ( format ) ) { return new SecretKeySpec ( encoded , algorithm ) ; } else if ( type == Type . PUBLIC && X509 . equals ( format ) ) { KeyFactory f = KeyFactory . getInstance ( algorithm ) ; return f . generatePublic ( new X509EncodedKeySpec ( encoded ) ) ; } else if ( type == Type . PRIVATE && PKCS8 . equals ( format ) ) { KeyFactory f = KeyFactory . getInstance ( algorithm ) ; return f . generatePrivate ( new PKCS8EncodedKeySpec ( encoded ) ) ; } else { throw new NotSerializableException ( "unrecognized type/format combination: " + type + "/" + format ) ; } } catch ( NotSerializableException nse ) { throw nse ; } catch ( Exception e ) { NotSerializableException nse = new NotSerializableException ( "java.security.Key: " + "[" + type + "] " + "[" + algorithm + "] " + "[" + format + "]" ) ; nse . initCause ( e ) ; throw nse ; } }
Resolve the Key object .