42
42
import java .security .spec .PKCS8EncodedKeySpec ;
43
43
import java .security .spec .X509EncodedKeySpec ;
44
44
import java .util .Arrays ;
45
+ import java .util .Base64 ;
45
46
import java .util .HashMap ;
46
47
import java .util .Map ;
47
48
48
49
import com .google .common .collect .ImmutableMap ;
49
50
import org .apache .solr .common .SolrException ;
50
- import org .apache .solr .common .util .Base64 ;
51
51
import org .slf4j .Logger ;
52
52
import org .slf4j .LoggerFactory ;
53
53
@@ -76,7 +76,7 @@ public String verify(String sig, ByteBuffer data) {
76
76
for (Map .Entry <String , PublicKey > entry : keys .entrySet ()) {
77
77
boolean verified ;
78
78
try {
79
- verified = CryptoKeys .verify (entry .getValue (), Base64 .base64ToByteArray (sig ), data );
79
+ verified = CryptoKeys .verify (entry .getValue (), Base64 .getDecoder (). decode (sig ), data );
80
80
log .debug ("verified {} " , verified );
81
81
if (verified ) return entry .getKey ();
82
82
} catch (Exception e ) {
@@ -94,7 +94,7 @@ public String verify(String sig, InputStream is) {
94
94
for (Map .Entry <String , PublicKey > entry : keys .entrySet ()) {
95
95
boolean verified ;
96
96
try {
97
- verified = CryptoKeys .verify (entry .getValue (), Base64 .base64ToByteArray (sig ), is );
97
+ verified = CryptoKeys .verify (entry .getValue (), Base64 .getDecoder (). decode (sig ), is );
98
98
log .debug ("verified {} " , verified );
99
99
if (verified ) return entry .getKey ();
100
100
} catch (Exception e ) {
@@ -258,7 +258,7 @@ public static String decodeAES(String base64CipherTxt, String pwd, final int key
258
258
final int CIPHERTEXT_OFFSET = SALT_OFFSET + SALT_SIZE ;
259
259
260
260
try {
261
- byte [] headerSaltAndCipherText = Base64 .base64ToByteArray (base64CipherTxt );
261
+ byte [] headerSaltAndCipherText = Base64 .getDecoder (). decode (base64CipherTxt );
262
262
263
263
// --- extract salt & encrypted ---
264
264
// header is "Salted__", ASCII encoded, if salt is being used (the default)
@@ -307,7 +307,7 @@ public static String decodeAES(String base64CipherTxt, String pwd, final int key
307
307
public static PublicKey deserializeX509PublicKey (String pubKey ) {
308
308
try {
309
309
KeyFactory keyFactory = KeyFactory .getInstance ("RSA" );
310
- X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec (Base64 .base64ToByteArray (pubKey ));
310
+ X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec (Base64 .getDecoder (). decode (pubKey ));
311
311
return keyFactory .generatePublic (publicKeySpec );
312
312
} catch (Exception e ) {
313
313
throw new SolrException (SolrException .ErrorCode .SERVER_ERROR ,e );
@@ -349,7 +349,7 @@ public RSAKeyPair() {
349
349
java .security .KeyPair keyPair = keyGen .genKeyPair ();
350
350
privateKey = keyPair .getPrivate ();
351
351
publicKey = keyPair .getPublic ();
352
- pubKeyStr = Base64 .byteArrayToBase64 (publicKey .getEncoded ());
352
+ pubKeyStr = Base64 .getEncoder (). encodeToString (publicKey .getEncoded ());
353
353
}
354
354
355
355
/**
@@ -365,7 +365,7 @@ public RSAKeyPair(URL privateKeyResourceName, URL publicKeyResourceName) throws
365
365
String privateString = new String (inPrivate .readAllBytes (), StandardCharsets .UTF_8 )
366
366
.replaceAll ("-----(BEGIN|END) PRIVATE KEY-----" , "" );
367
367
368
- PKCS8EncodedKeySpec privateSpec = new PKCS8EncodedKeySpec (java . util . Base64 .getMimeDecoder ().decode (privateString ));
368
+ PKCS8EncodedKeySpec privateSpec = new PKCS8EncodedKeySpec (Base64 .getMimeDecoder ().decode (privateString ));
369
369
KeyFactory rsaFactory = KeyFactory .getInstance ("RSA" );
370
370
privateKey = rsaFactory .generatePrivate (privateSpec );
371
371
} catch (NoSuchAlgorithmException e ) {
@@ -374,7 +374,7 @@ public RSAKeyPair(URL privateKeyResourceName, URL publicKeyResourceName) throws
374
374
375
375
try (InputStream inPublic = publicKeyResourceName .openStream ()) {
376
376
publicKey = getX509PublicKey (inPublic .readAllBytes ());
377
- pubKeyStr = Base64 .byteArrayToBase64 (publicKey .getEncoded ());
377
+ pubKeyStr = Base64 .getEncoder (). encodeToString (publicKey .getEncoded ());
378
378
}
379
379
}
380
380
0 commit comments