Skip to content

Commit 0828494

Browse files
author
Dave Syer
committed
Re-order while loop a bit
1 parent dc97ee1 commit 0828494

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/main/java/org/springframework/security/rsa/crypto/RsaRawEncryptor.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
import java.security.interfaces.RSAPublicKey;
2525

2626
import javax.crypto.Cipher;
27+
import sun.security.rsa.RSACore;
2728

2829
import org.springframework.security.crypto.encrypt.BytesEncryptor;
2930
import org.springframework.security.crypto.encrypt.TextEncryptor;
3031
import org.springframework.util.Assert;
3132
import org.springframework.util.Base64Utils;
32-
import sun.security.rsa.RSACore;
3333

3434
/**
3535
* @author Dave Syer
@@ -139,18 +139,17 @@ private static byte[] encrypt(byte[] text, PublicKey key, RsaAlgorithm alg) {
139139
}
140140
}
141141

142-
private static byte[] decrypt(byte[] text, PrivateKey key, RsaAlgorithm alg) {
142+
private static byte[] decrypt(byte[] text, RSAPrivateKey key, RsaAlgorithm alg) {
143143
ByteArrayOutputStream output = new ByteArrayOutputStream(text.length);
144144
try {
145145
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);
148147
int pos = 0;
149148
while (pos < text.length) {
149+
int limit = Math.min(text.length - pos, maxLength);
150150
cipher.init(Cipher.DECRYPT_MODE, key);
151151
cipher.update(text, pos, limit);
152152
pos += limit;
153-
limit = Math.min(text.length - pos, maxLength);
154153
byte[] buffer = cipher.doFinal();
155154
output.write(buffer, 0, buffer.length);
156155
}

0 commit comments

Comments
 (0)