/**
* Given a string key, either trim it down so its an appropriate size, or pad it to make it long enough
* @param theKey the key use
* @return a secret key based on the provided key string.
*/
private static SecretKey makeGoodKey(String theKey){
String aKey=theKey;
if (aKey.length() > 8) {
aKey=aKey.substring(0,8);
}
else if (aKey.length() < 8) {
while (aKey.length() < 8) {
aKey+="0";
}
}
return new SecretKeySpec(aKey.getBytes(),"DES");
}

Example 38

From project crest, under directory /core/src/main/java/org/codegist/crest/security/oauth/v1/.