diff options
| author | Kenny Root <kenny@the-b.org> | 2013-04-14 21:49:12 -0700 | 
|---|---|---|
| committer | Kenny Root <kenny@the-b.org> | 2013-04-14 21:49:12 -0700 | 
| commit | f631457a7cabe60275b34d4f82c81e9f94b6c28d (patch) | |
| tree | 28edd03017592f35d4d81b8b9dadbced8f22ef03 | |
| parent | c6cc322ab28ba55c0253c40b0774bba5a751bc35 (diff) | |
| download | connectbot-f631457a7cabe60275b34d4f82c81e9f94b6c28d.tar.gz connectbot-f631457a7cabe60275b34d4f82c81e9f94b6c28d.tar.bz2 connectbot-f631457a7cabe60275b34d4f82c81e9f94b6c28d.zip | |
Get rid of useless encoding methods
| -rw-r--r-- | src/org/connectbot/GeneratePubkeyActivity.java | 2 | ||||
| -rw-r--r-- | src/org/connectbot/util/PubkeyUtils.java | 27 | 
2 files changed, 11 insertions, 18 deletions
| diff --git a/src/org/connectbot/GeneratePubkeyActivity.java b/src/org/connectbot/GeneratePubkeyActivity.java index 94910e4..3a438c5 100644 --- a/src/org/connectbot/GeneratePubkeyActivity.java +++ b/src/org/connectbot/GeneratePubkeyActivity.java @@ -289,7 +289,7 @@ public class GeneratePubkeyActivity extends Activity implements OnEntropyGathere  				pubkey.setNickname(nickname.getText().toString());  				pubkey.setType(keyType);  				pubkey.setPrivateKey(PubkeyUtils.getEncodedPrivate(priv, secret)); -				pubkey.setPublicKey(PubkeyUtils.getEncodedPublic(pub)); +				pubkey.setPublicKey(pub.getEncoded());  				pubkey.setEncrypted(encrypted);  				pubkey.setStartup(unlockAtStartup.isChecked());  				pubkey.setConfirmUse(confirmUse.isChecked()); diff --git a/src/org/connectbot/util/PubkeyUtils.java b/src/org/connectbot/util/PubkeyUtils.java index 6e390b6..e7922bd 100644 --- a/src/org/connectbot/util/PubkeyUtils.java +++ b/src/org/connectbot/util/PubkeyUtils.java @@ -120,35 +120,28 @@ public class PubkeyUtils {  		return complete;  	} -	public static byte[] decrypt(byte[] complete, String secret) throws Exception { +	public static byte[] decrypt(byte[] saltAndCiphertext, String secret) throws Exception {  		try {  			byte[] salt = new byte[SALT_SIZE]; -			byte[] ciphertext = new byte[complete.length - salt.length]; +			byte[] ciphertext = new byte[saltAndCiphertext.length - salt.length]; -			System.arraycopy(complete, 0, salt, 0, salt.length); -			System.arraycopy(complete, salt.length, ciphertext, 0, ciphertext.length); +			System.arraycopy(saltAndCiphertext, 0, salt, 0, salt.length); +			System.arraycopy(saltAndCiphertext, salt.length, ciphertext, 0, ciphertext.length);  			return Encryptor.decrypt(salt, ITERATIONS, secret, ciphertext);  		} catch (Exception e) {  			Log.d("decrypt", "Could not decrypt with new method", e);  			// We might be using the old encryption method. -			return cipher(Cipher.DECRYPT_MODE, complete, secret.getBytes()); +			return cipher(Cipher.DECRYPT_MODE, saltAndCiphertext, secret.getBytes());  		}  	} -	public static byte[] getEncodedPublic(PublicKey pk) { -		return new X509EncodedKeySpec(pk.getEncoded()).getEncoded(); -	} - -	public static byte[] getEncodedPrivate(PrivateKey pk) { -		return new PKCS8EncodedKeySpec(pk.getEncoded()).getEncoded(); -	} -  	public static byte[] getEncodedPrivate(PrivateKey pk, String secret) throws Exception { -		if (secret.length() > 0) -			return encrypt(getEncodedPrivate(pk), secret); -		else -			return getEncodedPrivate(pk); +		final byte[] encoded = pk.getEncoded(); +		if (secret == null || secret.length() == 0) { +			return encoded; +		} +		return encrypt(pk.getEncoded(), secret);  	}  	public static PrivateKey decodePrivate(byte[] encoded, String keyType) throws NoSuchAlgorithmException, InvalidKeySpecException { | 
