1 package snow.crypto; 2 3 import snow.utils.storage.*; 4 5 import java.security.*; 6 import java.security.spec.*; 7 import javax.crypto.spec.*; 8 import javax.crypto.*; 9 import java.io.*; 10 import java.util.zip.*; 11 import java.util.*; 12 13 14 public final class SecretKeyUtilities 15 { 16 17 private SecretKeyUtilities() 18 { 19 20 } 22 29 public static SecretKey generateSecretKeyFromPassphrase(byte[] pass, int length_in_bytes) throws Exception 30 { 31 byte[] hash = CryptoUtilities.SHA1Hash(pass); 34 byte[] wk = new byte[length_in_bytes]; 35 System.arraycopy(hash, 0, wk, 0, wk.length); 38 SecretKeySpec skeySpec = new SecretKeySpec(wk, "Blowfish"); 39 41 return skeySpec; 42 } 43 44 46 public static SecretKeyID computeSignature(SecretKey key) 47 { 48 try 49 { 50 byte[] hashpass = CryptoUtilities.SHA1Hash(key.getEncoded()); 51 byte[] sign = new byte[4]; 52 System.arraycopy(hashpass, 0, sign, 0, sign.length); 53 SecretKeyID ski = new SecretKeyID(sign, key.getEncoded().length); 54 return ski; 55 } 56 catch(Exception e) 57 { 58 throw new RuntimeException ("Cannot compute key signature"); 59 } 60 } 61 62 63 64 } | Popular Tags |