title: What's the difference between a Key and a KeySpec?
body: <p>In the Java crypto libraries, there are two different representations of a key - <a href="http://docs.oracle.com/javase/8/docs/api/java/security/Key.html" rel="noreferrer"><code>Key</code></a> and <a href="http://docs.oracle.com/javase/8/docs/api/java/security/spec/KeySpec.html" rel="noreferrer"><code>KeySpec</code></a>. The docs imply there's a difference between the two - a <code>KeySpec</code> is 'transparent' (whatever that means), but has no methods, whereas <code>Key</code> has got a <code>getEncoded</code> method. You're meant to use a <a href="http://docs.oracle.com/javase/8/docs/api/java/security/KeyFactory.html" rel="noreferrer"><code>KeyFactory</code></a> to convert between the two (and it indeed has got a <code>getKeySpec</code> method to convert).</p>
  
  <p>However, <code>SecretKeySpec</code> implements both <code>Key</code> and <code>KeySpec</code>! But there is a <code>SecretKeyFactory</code> class as well, that doesn't inherit off <code>KeyFactory</code>.</p>
  
  <p>All this has left me thoroughly confused. What's the different between a <code>Key</code> and a <code>KeySpec</code>, and how does <code>SecretKeySpec</code> and <code>SecretKeyFactory</code> come into it?</p>