From 88ceee62acf91eb9c6865cb6bfc911419b70fc69 Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 6 Jan 2015 23:54:15 +0200 Subject: [PATCH] getRSAPublicKey now returns a copy of the public key rather than the object itself --- src/nodash/models/NoUser.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nodash/models/NoUser.java b/src/nodash/models/NoUser.java index 9548049..7fc7cd4 100644 --- a/src/nodash/models/NoUser.java +++ b/src/nodash/models/NoUser.java @@ -35,6 +35,7 @@ import java.security.NoSuchProviderException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.SecureRandom; +import java.security.spec.RSAPublicKeySpec; import java.util.ArrayList; import javax.crypto.BadPaddingException; @@ -157,7 +158,11 @@ public class NoUser implements Serializable { } public final PublicKey getRSAPublicKey() { - return (RSAPublicKeyImpl) this.publicKey; + try { + return new RSAPublicKeyImpl(this.getModulus(), this.getPublicExponent()); + } catch (InvalidKeyException e) { + throw new NoDashFatalException("Invalid key while re-generating a RSAPublicKey.", e); + } } private final byte[] decryptRSA(byte[] data) throws InvalidKeyException, IllegalBlockSizeException, BadPaddingException {