Skip to content

Commit 304865b

Browse files
committed
Took substring of public key and created buffer in XOR
Signed-off-by: S V <vats02581@gmail.com>
1 parent 7025c71 commit 304865b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/authentication/AuthUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,14 @@ private static byte[] allBytesXor(byte[] left, byte[] right) {
115115

116116
static byte[] rotatingXor(byte[] password, byte[] seedBytes) {
117117
int seedLength = seedBytes.length;
118+
int passwordLength = password.length;
119+
byte[] buffer = new byte[passwordLength];
118120

119-
for (int i = 0; i < password.length; i++) {
120-
password[i] ^= seedBytes[i % seedLength];
121+
for (int i = 0; i < passwordLength; i++) {
122+
buffer[i] = (byte)(password[i] ^ seedBytes[i % seedLength]);
121123
}
122124

123-
return password;
125+
return buffer;
124126
}
125127

126128
private AuthUtils() { }

r2dbc-mysql/src/main/java/io/asyncer/r2dbc/mysql/authentication/MySqlAuthProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ static byte[] rsaEncryption(byte[] bytesToEncrypt, String serverRsaPublicKeyFile
158158

159159
String key = new String(Files.readAllBytes(Paths.get(serverRsaPublicKeyFile)), Charset.defaultCharset());
160160

161+
int startIndex = key.indexOf("-----BEGIN PUBLIC KEY-----");
162+
int endIndex = key.indexOf("-----END PUBLIC KEY-----") + 23;
163+
key = key.substring(startIndex, endIndex+1);
161164
String publicKeyPEM = key
162165
.replace("-----BEGIN PUBLIC KEY-----", "")
163166
.replaceAll(System.lineSeparator(), "")

0 commit comments

Comments
 (0)