renaming to adhere to GoogleStyle conventions
This commit is contained in:
@@ -77,7 +77,7 @@ public final class NoUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] getPBEKeyFromPassword(char[] password) {
|
||||
private static byte[] getPbeKeyFromPassword(char[] password) {
|
||||
SecretKeyFactory skf;
|
||||
try {
|
||||
skf = SecretKeyFactory.getInstance(NoUtil.PBE_TYPE);
|
||||
@@ -106,14 +106,14 @@ public final class NoUtil {
|
||||
|
||||
public static byte[] decrypt(byte[] data, char[] password) throws IllegalBlockSizeException,
|
||||
BadPaddingException {
|
||||
byte[] passwordByte = NoUtil.getPBEKeyFromPassword(password);
|
||||
byte[] passwordByte = NoUtil.getPbeKeyFromPassword(password);
|
||||
byte[] response = NoUtil.decrypt(NoUtil.decrypt(data), passwordByte);
|
||||
NoUtil.wipeBytes(passwordByte);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static byte[] encrypt(byte[] data, char[] password) {
|
||||
byte[] passwordByte = NoUtil.getPBEKeyFromPassword(password);
|
||||
byte[] passwordByte = NoUtil.getPbeKeyFromPassword(password);
|
||||
byte[] response = NoUtil.encrypt(NoUtil.encrypt(data, passwordByte));
|
||||
NoUtil.wipeBytes(passwordByte);
|
||||
return response;
|
||||
@@ -172,7 +172,7 @@ public final class NoUtil {
|
||||
return NoUtil.decrypt(data, NoCore.config.getSecretKey().getEncoded());
|
||||
}
|
||||
|
||||
public static byte[] encryptRSA(byte[] data, PublicKey publicKey) {
|
||||
public static byte[] encryptRsa(byte[] data, PublicKey publicKey) {
|
||||
Cipher cipher;
|
||||
try {
|
||||
cipher = Cipher.getInstance(NoUtil.CIPHER_RSA_TYPE);
|
||||
@@ -194,7 +194,7 @@ public final class NoUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] decryptRSA(byte[] data, PrivateKey privateKey) throws InvalidKeyException,
|
||||
public static byte[] decryptRsa(byte[] data, PrivateKey privateKey) throws InvalidKeyException,
|
||||
IllegalBlockSizeException, BadPaddingException {
|
||||
Cipher cipher;
|
||||
try {
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class NoSessionSphere {
|
||||
|
||||
public static void shred(byte[] encryptedUUID) {
|
||||
try {
|
||||
UUID uuid = NoSession.decryptUUID(encryptedUUID);
|
||||
UUID uuid = NoSession.decryptUuid(encryptedUUID);
|
||||
if (NoSessionSphere.sessions.containsKey(uuid)) {
|
||||
NoSession session = NoSessionSphere.sessions.get(uuid);
|
||||
NoByteSetSphere.addList(session.incoming, session.current.getRSAPublicKey());
|
||||
@@ -116,12 +116,12 @@ public final class NoSessionSphere {
|
||||
/* Will set to 2.1[MODIFIED] or 2.2[IDLE] */
|
||||
|
||||
/* Precursor to 3.; allow website to associate user session with a cookie. */
|
||||
return session.getEncryptedUUID();
|
||||
return session.getEncryptedUuid();
|
||||
}
|
||||
|
||||
public static NoUser getUser(byte[] encryptedUUID) throws NoDashSessionBadUUIDException,
|
||||
NoSessionExpiredException, NoSessionConfirmedException {
|
||||
UUID uuid = NoSession.decryptUUID(encryptedUUID);
|
||||
UUID uuid = NoSession.decryptUuid(encryptedUUID);
|
||||
if (NoSessionSphere.sessions.containsKey(uuid)) {
|
||||
NoSessionSphere.pruneSingle(uuid);
|
||||
try {
|
||||
@@ -135,7 +135,7 @@ public final class NoSessionSphere {
|
||||
|
||||
public static NoState getState(byte[] encryptedUUID) throws NoDashSessionBadUUIDException,
|
||||
NoSessionExpiredException, NoSessionConfirmedException {
|
||||
UUID uuid = NoSession.decryptUUID(encryptedUUID);
|
||||
UUID uuid = NoSession.decryptUuid(encryptedUUID);
|
||||
if (NoSessionSphere.sessions.containsKey(uuid)) {
|
||||
NoSessionSphere.pruneSingle(uuid);
|
||||
NoSession session = NoSessionSphere.sessions.get(uuid);
|
||||
@@ -147,7 +147,7 @@ public final class NoSessionSphere {
|
||||
public static synchronized byte[] save(byte[] encryptedUUID, char[] password)
|
||||
throws NoDashSessionBadUUIDException, NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotChangedException, NoSessionAlreadyAwaitingConfirmationException {
|
||||
UUID uuid = NoSession.decryptUUID(encryptedUUID);
|
||||
UUID uuid = NoSession.decryptUuid(encryptedUUID);
|
||||
if (NoSessionSphere.sessions.containsKey(uuid)) {
|
||||
NoSessionSphere.pruneSingle(uuid);
|
||||
NoSession session = NoSessionSphere.sessions.get(uuid);
|
||||
@@ -165,7 +165,7 @@ public final class NoSessionSphere {
|
||||
public static synchronized void confirm(byte[] encryptedUUID, char[] password, byte[] data)
|
||||
throws NoDashSessionBadUUIDException, NoSessionExpiredException, NoSessionConfirmedException,
|
||||
NoSessionNotAwaitingConfirmationException, NoUserNotValidException {
|
||||
UUID uuid = NoSession.decryptUUID(encryptedUUID);
|
||||
UUID uuid = NoSession.decryptUuid(encryptedUUID);
|
||||
if (NoSessionSphere.sessions.containsKey(uuid)) {
|
||||
NoSessionSphere.pruneSingle(uuid);
|
||||
NoSession session = NoSessionSphere.sessions.get(uuid);
|
||||
@@ -179,7 +179,7 @@ public final class NoSessionSphere {
|
||||
NoSession session = new NoSession(user);
|
||||
NoSessionSphere.sessions.put(session.uuid, session);
|
||||
try {
|
||||
byte[] cookie = session.getEncryptedUUID();
|
||||
byte[] cookie = session.getEncryptedUuid();
|
||||
return new NoRegister(cookie, NoSessionSphere.save(cookie, password));
|
||||
} catch (NoDashSessionBadUUIDException e) {
|
||||
throw new NoDashFatalException("Immediately generated cookie throwing bad cookie error.", e);
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class NoInfluence implements Serializable {
|
||||
keyGen.init(NoUtil.AES_STRENGTH);
|
||||
SecretKey secretKey = keyGen.generateKey();
|
||||
byte[] key = secretKey.getEncoded();
|
||||
byte[] encryptedKey = NoUtil.encryptRSA(key, publicKey);
|
||||
byte[] encryptedKey = NoUtil.encryptRsa(key, publicKey);
|
||||
byte[] data = this.getEncrypted(key);
|
||||
NoUtil.wipeBytes(key);
|
||||
return new NoByteSet(encryptedKey, data);
|
||||
|
||||
@@ -183,20 +183,20 @@ public final class NoSession implements Serializable {
|
||||
return this.current;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public String getUUIDAsString() {
|
||||
public String getUuidAsString() {
|
||||
return this.uuid.toString();
|
||||
}
|
||||
|
||||
public byte[] getEncryptedUUID() {
|
||||
public byte[] getEncryptedUuid() {
|
||||
return NoUtil.encrypt(Base64.encodeBase64(this.uuid.toString().getBytes()));
|
||||
}
|
||||
|
||||
public String getEncryptedUUIDAsString() {
|
||||
return new String(this.getEncryptedUUID());
|
||||
public String getEncryptedUuidAsString() {
|
||||
return new String(this.getEncryptedUuid());
|
||||
}
|
||||
|
||||
public byte[] getOriginalHash() {
|
||||
@@ -207,7 +207,7 @@ public final class NoSession implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public static UUID decryptUUID(byte[] data) throws NoDashSessionBadUUIDException {
|
||||
public static UUID decryptUuid(byte[] data) throws NoDashSessionBadUUIDException {
|
||||
if (data == null) {
|
||||
throw new NoDashSessionBadUUIDException();
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class NoUser implements Serializable {
|
||||
|
||||
private final byte[] decryptRSA(byte[] data) throws InvalidKeyException,
|
||||
IllegalBlockSizeException, BadPaddingException {
|
||||
return NoUtil.decryptRSA(data, this.privateKey);
|
||||
return NoUtil.decryptRsa(data, this.privateKey);
|
||||
}
|
||||
|
||||
public static NoUser createUserFromFile(byte[] data, char[] password)
|
||||
|
||||
@@ -124,7 +124,7 @@ public class NoUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testByteKeyEncryptionDecryptionAES() throws IllegalBlockSizeException, BadPaddingException {
|
||||
public void testByteKeyEncryptionDecryptionAes() throws IllegalBlockSizeException, BadPaddingException {
|
||||
final byte[] originalBytes = {'s', 'o', 'm', 'e', 'b', 'y', 't', 'e', 's'};
|
||||
final byte[] originalByteKey = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
|
||||
|
||||
@@ -171,7 +171,7 @@ public class NoUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharKeyEncryptionDecryptionAES() throws IllegalBlockSizeException, BadPaddingException {
|
||||
public void testCharKeyEncryptionDecryptionAes() throws IllegalBlockSizeException, BadPaddingException {
|
||||
final byte[] originalBytes = {'s', 'o', 'm', 'e', 'b', 'y', 't', 'e', 's'};
|
||||
final char[] originalCharKey = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
|
||||
|
||||
@@ -215,7 +215,7 @@ public class NoUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoKeyEncryptionDecryptionAES() throws IllegalBlockSizeException, BadPaddingException {
|
||||
public void testNoKeyEncryptionDecryptionAes() throws IllegalBlockSizeException, BadPaddingException {
|
||||
final byte[] originalBytes = {'s', 'o', 'm', 'e', 'b', 'y', 't', 'e', 's'};
|
||||
byte[] bytes = Arrays.copyOf(originalBytes, originalBytes.length);
|
||||
|
||||
@@ -232,7 +232,7 @@ public class NoUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncryptionDecryptionRSA() throws NoSuchAlgorithmException,
|
||||
public void testEncryptionDecryptionRsa() throws NoSuchAlgorithmException,
|
||||
NoSuchProviderException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
||||
KeyPairGenerator kpg = KeyPairGenerator.getInstance(NoUtil.KEYPAIR_ALGORITHM);
|
||||
kpg.initialize(NoUtil.RSA_STRENGTH,
|
||||
@@ -245,15 +245,15 @@ public class NoUtilTest {
|
||||
final byte[] originalBytes = {'s', 'o', 'm', 'e', 'b', 'y', 't', 'e', 's'};
|
||||
byte[] bytes = Arrays.copyOf(originalBytes, originalBytes.length);
|
||||
|
||||
byte[] encrypted = NoUtil.encryptRSA(bytes, keyPair.getPublic());
|
||||
byte[] encrypted = NoUtil.encryptRsa(bytes, keyPair.getPublic());
|
||||
try {
|
||||
NoUtil.decryptRSA(encrypted, keyPair2.getPrivate());
|
||||
NoUtil.decryptRsa(encrypted, keyPair2.getPrivate());
|
||||
fail("Did not throw exception with incorrect private key.");
|
||||
} catch (BadPaddingException e) {
|
||||
// Do nothing, correct
|
||||
}
|
||||
|
||||
byte[] decrypted = NoUtil.decryptRSA(encrypted, keyPair.getPrivate());
|
||||
byte[] decrypted = NoUtil.decryptRsa(encrypted, keyPair.getPrivate());
|
||||
assertTrue(Arrays.equals(originalBytes, decrypted));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user