27 28 import java.security.*; 29 import java.security.spec.AlgorithmParameterSpec; 30 31 import javax.crypto.*; 32 import javax.crypto.spec.SecretKeySpec; 33 34 import sun.security.internal.spec.TlsRsaPremasterSecretParameterSpec; 35 36 /** 37 * KeyGenerator implementation for the SSL/TLS RSA premaster secret. 38 * 39 * @author Andreas Sterbenz 40 * @since 1.6 41 */ 42 public final class TlsRsaPremasterSecretGenerator extends KeyGeneratorSpi { 43 44 private final static String MSG = "TlsRsaPremasterSecretGenerator must be " 45 + "initialized using a TlsRsaPremasterSecretParameterSpec"; 46 47 private TlsRsaPremasterSecretParameterSpec spec; 48 private SecureRandom random; 49 50 public TlsRsaPremasterSecretGenerator() { 51 } 52 53 protected void engineInit(SecureRandom random) { 54 throw new InvalidParameterException(MSG); 55 } 56 57 protected void engineInit(AlgorithmParameterSpec params, 58 SecureRandom random) throws InvalidAlgorithmParameterException { 59 if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) { 60 throw new InvalidAlgorithmParameterException(MSG); 61 } 62 this.spec = (TlsRsaPremasterSecretParameterSpec)params; 63 this.random = random; 64 } 65 66 protected void engineInit(int keysize, SecureRandom random) { 67 throw new InvalidParameterException(MSG); 68 } 69 70 // Only can be used in client side to generate TLS RSA premaster secret. 71 protected SecretKey engineGenerateKey() { 72 if (spec == null) { 73 throw new IllegalStateException( 74 "TlsRsaPremasterSecretGenerator must be initialized"); 75 } 76 | 27 28 import java.security.*; 29 import java.security.spec.AlgorithmParameterSpec; 30 31 import javax.crypto.*; 32 import javax.crypto.spec.SecretKeySpec; 33 34 import sun.security.internal.spec.TlsRsaPremasterSecretParameterSpec; 35 36 /** 37 * KeyGenerator implementation for the SSL/TLS RSA premaster secret. 38 * 39 * @author Andreas Sterbenz 40 * @since 1.6 41 */ 42 public final class TlsRsaPremasterSecretGenerator extends KeyGeneratorSpi { 43 44 private final static String MSG = "TlsRsaPremasterSecretGenerator must be " 45 + "initialized using a TlsRsaPremasterSecretParameterSpec"; 46 47 @SuppressWarnings("deprecation") 48 private TlsRsaPremasterSecretParameterSpec spec; 49 private SecureRandom random; 50 51 public TlsRsaPremasterSecretGenerator() { 52 } 53 54 protected void engineInit(SecureRandom random) { 55 throw new InvalidParameterException(MSG); 56 } 57 58 @SuppressWarnings("deprecation") 59 protected void engineInit(AlgorithmParameterSpec params, 60 SecureRandom random) throws InvalidAlgorithmParameterException { 61 if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) { 62 throw new InvalidAlgorithmParameterException(MSG); 63 } 64 this.spec = (TlsRsaPremasterSecretParameterSpec)params; 65 this.random = random; 66 } 67 68 protected void engineInit(int keysize, SecureRandom random) { 69 throw new InvalidParameterException(MSG); 70 } 71 72 // Only can be used in client side to generate TLS RSA premaster secret. 73 protected SecretKey engineGenerateKey() { 74 if (spec == null) { 75 throw new IllegalStateException( 76 "TlsRsaPremasterSecretGenerator must be initialized"); 77 } 78 |