|
24 | 24 | import java.security.interfaces.RSAPublicKey;
|
25 | 25 |
|
26 | 26 | import javax.crypto.Cipher;
|
| 27 | +import sun.security.rsa.RSACore; |
27 | 28 |
|
28 | 29 | import org.springframework.security.crypto.encrypt.BytesEncryptor;
|
29 | 30 | import org.springframework.security.crypto.encrypt.TextEncryptor;
|
30 | 31 | import org.springframework.util.Assert;
|
31 | 32 | import org.springframework.util.Base64Utils;
|
32 |
| -import sun.security.rsa.RSACore; |
33 | 33 |
|
34 | 34 | /**
|
35 | 35 | * @author Dave Syer
|
@@ -139,18 +139,17 @@ private static byte[] encrypt(byte[] text, PublicKey key, RsaAlgorithm alg) {
|
139 | 139 | }
|
140 | 140 | }
|
141 | 141 |
|
142 |
| - private static byte[] decrypt(byte[] text, PrivateKey key, RsaAlgorithm alg) { |
| 142 | + private static byte[] decrypt(byte[] text, RSAPrivateKey key, RsaAlgorithm alg) { |
143 | 143 | ByteArrayOutputStream output = new ByteArrayOutputStream(text.length);
|
144 | 144 | try {
|
145 | 145 | final Cipher cipher = Cipher.getInstance(alg.getJceName());
|
146 |
| - int maxLength = RSACore.getByteLength((RSAPrivateKey) key); |
147 |
| - int limit = Math.min(text.length, maxLength); |
| 146 | + int maxLength = RSACore.getByteLength(key); |
148 | 147 | int pos = 0;
|
149 | 148 | while (pos < text.length) {
|
| 149 | + int limit = Math.min(text.length - pos, maxLength); |
150 | 150 | cipher.init(Cipher.DECRYPT_MODE, key);
|
151 | 151 | cipher.update(text, pos, limit);
|
152 | 152 | pos += limit;
|
153 |
| - limit = Math.min(text.length - pos, maxLength); |
154 | 153 | byte[] buffer = cipher.doFinal();
|
155 | 154 | output.write(buffer, 0, buffer.length);
|
156 | 155 | }
|
|
0 commit comments