diff options
Diffstat (limited to 'src/main/java/org/bouncycastle/crypto/tls/DefaultTlsEncryptionCredentials.java')
-rw-r--r-- | src/main/java/org/bouncycastle/crypto/tls/DefaultTlsEncryptionCredentials.java | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/main/java/org/bouncycastle/crypto/tls/DefaultTlsEncryptionCredentials.java b/src/main/java/org/bouncycastle/crypto/tls/DefaultTlsEncryptionCredentials.java index a9e95ea0..c21a555d 100644 --- a/src/main/java/org/bouncycastle/crypto/tls/DefaultTlsEncryptionCredentials.java +++ b/src/main/java/org/bouncycastle/crypto/tls/DefaultTlsEncryptionCredentials.java @@ -9,28 +9,38 @@ import org.bouncycastle.crypto.params.AsymmetricKeyParameter; import org.bouncycastle.crypto.params.ParametersWithRandom;
import org.bouncycastle.crypto.params.RSAKeyParameters;
-public class DefaultTlsEncryptionCredentials implements TlsEncryptionCredentials {
+public class DefaultTlsEncryptionCredentials
+ implements TlsEncryptionCredentials
+{
protected TlsContext context;
protected Certificate certificate;
protected AsymmetricKeyParameter privateKey;
public DefaultTlsEncryptionCredentials(TlsContext context, Certificate certificate,
- AsymmetricKeyParameter privateKey) {
- if (certificate == null) {
+ AsymmetricKeyParameter privateKey)
+ {
+ if (certificate == null)
+ {
throw new IllegalArgumentException("'certificate' cannot be null");
}
- if (certificate.isEmpty()) {
+ if (certificate.isEmpty())
+ {
throw new IllegalArgumentException("'certificate' cannot be empty");
}
- if (privateKey == null) {
+ if (privateKey == null)
+ {
throw new IllegalArgumentException("'privateKey' cannot be null");
}
- if (!privateKey.isPrivate()) {
+ if (!privateKey.isPrivate())
+ {
throw new IllegalArgumentException("'privateKey' must be private");
}
- if (privateKey instanceof RSAKeyParameters) {
- } else {
+ if (privateKey instanceof RSAKeyParameters)
+ {
+ }
+ else
+ {
throw new IllegalArgumentException("'privateKey' type not supported: "
+ privateKey.getClass().getName());
}
@@ -40,19 +50,25 @@ public class DefaultTlsEncryptionCredentials implements TlsEncryptionCredentials this.privateKey = privateKey;
}
- public Certificate getCertificate() {
+ public Certificate getCertificate()
+ {
return certificate;
}
- public byte[] decryptPreMasterSecret(byte[] encryptedPreMasterSecret) throws IOException {
+ public byte[] decryptPreMasterSecret(byte[] encryptedPreMasterSecret)
+ throws IOException
+ {
PKCS1Encoding encoding = new PKCS1Encoding(new RSABlindedEngine());
encoding.init(false, new ParametersWithRandom(this.privateKey, context.getSecureRandom()));
- try {
+ try
+ {
return encoding.processBlock(encryptedPreMasterSecret, 0,
encryptedPreMasterSecret.length);
- } catch (InvalidCipherTextException e) {
+ }
+ catch (InvalidCipherTextException e)
+ {
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
}
}
|