diff --git a/pom.xml b/pom.xml
index 6287efc..84ff0de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,17 +11,17 @@
- bukkit
- http://repo.bukkit.org/content/groups/public/
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
- org.bukkit
- bukkit
- 1.7.9-R0.2
+ org.spigotmc
+ spigot-api
+ 1.8.8-R0.1-SNAPSHOTjarcompile
@@ -36,8 +36,8 @@
maven-compiler-plugin2.3.2
- 1.7
- 1.7
+ 8
+ 8
diff --git a/src/main/java/com/vexsoftware/votifier/Votifier.java b/src/main/java/com/vexsoftware/votifier/Votifier.java
index 6e7fe54..f791c4d 100644
--- a/src/main/java/com/vexsoftware/votifier/Votifier.java
+++ b/src/main/java/com/vexsoftware/votifier/Votifier.java
@@ -85,7 +85,7 @@ public void onEnable() {
File config = new File(getDataFolder() + "/config.yml");
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(config);
File rsaDirectory = new File(getDataFolder() + "/rsa");
- // Replace to remove a bug with Windows paths - SmilingDevil
+ // Replace it to remove a bug with Windows paths - SmilingDevil
String listenerDirectory = getDataFolder().toString()
.replace("\\", "/") + "/listeners";
@@ -100,7 +100,7 @@ public void onEnable() {
hostAddr = "0.0.0.0";
/*
- * Create configuration file if it does not exists; otherwise, load it
+ * Create a configuration file if it does not exist; otherwise, load it
*/
if (!config.exists()) {
try {
diff --git a/src/main/java/com/vexsoftware/votifier/crypto/RSAIO.java b/src/main/java/com/vexsoftware/votifier/crypto/RSAIO.java
index a5727ee..c380e68 100644
--- a/src/main/java/com/vexsoftware/votifier/crypto/RSAIO.java
+++ b/src/main/java/com/vexsoftware/votifier/crypto/RSAIO.java
@@ -1,23 +1,6 @@
-/*
- * Copyright (C) 2011 Vex Software LLC
- * This file is part of Votifier.
- *
- * Votifier is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Votifier is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Votifier. If not, see .
- */
-
package com.vexsoftware.votifier.crypto;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -27,85 +10,82 @@
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
-
-import javax.xml.bind.DatatypeConverter;
+import java.util.Base64;
/**
* Static utility methods for saving and loading RSA key pairs.
- *
- * @author Blake Beaupain
+ *
+ * @author Blake Beaupain, mzcy_ (Recode, don't use javax classes)
*/
public class RSAIO {
/**
* Saves the key pair to the disk.
- *
- * @param directory
- * The directory to save to
- * @param keyPair
- * The key pair to save
- * @throws Exception
- * If an error occurs
+ *
+ * @param directory The directory to save to
+ * @param keyPair The key pair to save
+ * @throws Exception If an error occurs
*/
public static void save(File directory, KeyPair keyPair) throws Exception {
PrivateKey privateKey = keyPair.getPrivate();
PublicKey publicKey = keyPair.getPublic();
// Store the public key.
- X509EncodedKeySpec publicSpec = new X509EncodedKeySpec(
- publicKey.getEncoded());
- FileOutputStream out = new FileOutputStream(directory + "/public.key");
- out.write(DatatypeConverter.printBase64Binary(publicSpec.getEncoded())
- .getBytes());
- out.close();
+ X509EncodedKeySpec publicSpec = new X509EncodedKeySpec(publicKey.getEncoded());
+ try (FileOutputStream out = new FileOutputStream(new File(directory, "public.key"))) {
+ out.write(Base64.getEncoder().encode(publicSpec.getEncoded()));
+ }
// Store the private key.
- PKCS8EncodedKeySpec privateSpec = new PKCS8EncodedKeySpec(
- privateKey.getEncoded());
- out = new FileOutputStream(directory + "/private.key");
- out.write(DatatypeConverter.printBase64Binary(privateSpec.getEncoded())
- .getBytes());
- out.close();
+ PKCS8EncodedKeySpec privateSpec = new PKCS8EncodedKeySpec(privateKey.getEncoded());
+ try (FileOutputStream out = new FileOutputStream(new File(directory, "private.key"))) {
+ out.write(Base64.getEncoder().encode(privateSpec.getEncoded()));
+ }
}
/**
* Loads an RSA key pair from a directory. The directory must have the files
* "public.key" and "private.key".
- *
- * @param directory
- * The directory to load from
+ *
+ * @param directory The directory to load from
* @return The key pair
- * @throws Exception
- * If an error occurs
+ * @throws Exception If an error occurs
*/
public static KeyPair load(File directory) throws Exception {
// Read the public key file.
- File publicKeyFile = new File(directory + "/public.key");
- FileInputStream in = new FileInputStream(directory + "/public.key");
- byte[] encodedPublicKey = new byte[(int) publicKeyFile.length()];
- in.read(encodedPublicKey);
- encodedPublicKey = DatatypeConverter.parseBase64Binary(new String(
- encodedPublicKey));
- in.close();
+ File publicKeyFile = new File(directory, "public.key");
+ byte[] encodedPublicKey;
+ try (FileInputStream in = new FileInputStream(publicKeyFile)) {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ int nRead;
+ byte[] data = new byte[16384];
+ while ((nRead = in.read(data, 0, data.length)) != -1) {
+ buffer.write(data, 0, nRead);
+ }
+ encodedPublicKey = buffer.toByteArray();
+ }
+ byte[] decodedPublicKey = Base64.getDecoder().decode(encodedPublicKey);
// Read the private key file.
- File privateKeyFile = new File(directory + "/private.key");
- in = new FileInputStream(directory + "/private.key");
- byte[] encodedPrivateKey = new byte[(int) privateKeyFile.length()];
- in.read(encodedPrivateKey);
- encodedPrivateKey = DatatypeConverter.parseBase64Binary(new String(
- encodedPrivateKey));
- in.close();
+ File privateKeyFile = new File(directory, "private.key");
+ byte[] encodedPrivateKey;
+ try (FileInputStream in = new FileInputStream(privateKeyFile)) {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ int nRead;
+ byte[] data = new byte[16384];
+ while ((nRead = in.read(data, 0, data.length)) != -1) {
+ buffer.write(data, 0, nRead);
+ }
+ encodedPrivateKey = buffer.toByteArray();
+ }
+ byte[] decodedPrivateKey = Base64.getDecoder().decode(encodedPrivateKey);
// Instantiate and return the key pair.
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
- X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(
- encodedPublicKey);
+ X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(decodedPublicKey);
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
- PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(
- encodedPrivateKey);
+ PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(decodedPrivateKey);
PrivateKey privateKey = keyFactory.generatePrivate(privateKeySpec);
return new KeyPair(publicKey, privateKey);
}
-
-}
+}
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 0762eea..44a1743 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -2,4 +2,4 @@ name: Votifier
main: com.vexsoftware.votifier.Votifier
version: maven-version-number
description: A plugin that gets notified when votes are made for the server on toplists.
-authors: [blakeman8192, Kramer]
\ No newline at end of file
+authors: [blakeman8192, Kramer, mzcy_]
\ No newline at end of file