Skip to content

Commit

Permalink
Import javax.crypto.Cipher instead of com.jcraft.jsch.Cipher.
Browse files Browse the repository at this point in the history
  • Loading branch information
norrisjeremy committed Jan 22, 2024
1 parent 604203c commit 8455767
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 90 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/AES128CBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AES128CBC implements Cipher {
public class AES128CBC implements com.jcraft.jsch.Cipher {
private static final int ivsize = 16;
private static final int bsize = 16;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand Down Expand Up @@ -61,9 +61,10 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {

try {
SecretKeySpec keyspec = new SecretKeySpec(key, "AES");
cipher = javax.crypto.Cipher.getInstance("AES/CBC/NoPadding");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), keyspec, new IvParameterSpec(iv));
cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
keyspec, new IvParameterSpec(iv));
} catch (Exception e) {
cipher = null;
throw e;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/AES128CTR.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AES128CTR implements Cipher {
public class AES128CTR implements com.jcraft.jsch.Cipher {
private static final int ivsize = 16;
private static final int bsize = 16;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand Down Expand Up @@ -61,9 +61,10 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {

try {
SecretKeySpec keyspec = new SecretKeySpec(key, "AES");
cipher = javax.crypto.Cipher.getInstance("AES/CTR/NoPadding");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), keyspec, new IvParameterSpec(iv));
cipher = Cipher.getInstance("AES/CTR/NoPadding");
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
keyspec, new IvParameterSpec(iv));
} catch (Exception e) {
cipher = null;
throw e;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/AES192CBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AES192CBC implements Cipher {
public class AES192CBC implements com.jcraft.jsch.Cipher {
private static final int ivsize = 16;
private static final int bsize = 24;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand All @@ -60,9 +60,10 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {
}
try {
SecretKeySpec keyspec = new SecretKeySpec(key, "AES");
cipher = javax.crypto.Cipher.getInstance("AES/CBC/NoPadding");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), keyspec, new IvParameterSpec(iv));
cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
keyspec, new IvParameterSpec(iv));
} catch (Exception e) {
cipher = null;
throw e;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/AES192CTR.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AES192CTR implements Cipher {
public class AES192CTR implements com.jcraft.jsch.Cipher {
private static final int ivsize = 16;
private static final int bsize = 24;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand All @@ -60,9 +60,10 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {
}
try {
SecretKeySpec keyspec = new SecretKeySpec(key, "AES");
cipher = javax.crypto.Cipher.getInstance("AES/CTR/NoPadding");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), keyspec, new IvParameterSpec(iv));
cipher = Cipher.getInstance("AES/CTR/NoPadding");
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
keyspec, new IvParameterSpec(iv));
} catch (Exception e) {
cipher = null;
throw e;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/AES256CBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AES256CBC implements Cipher {
public class AES256CBC implements com.jcraft.jsch.Cipher {
private static final int ivsize = 16;
private static final int bsize = 32;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand All @@ -60,9 +60,10 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {
}
try {
SecretKeySpec keyspec = new SecretKeySpec(key, "AES");
cipher = javax.crypto.Cipher.getInstance("AES/CBC/NoPadding");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), keyspec, new IvParameterSpec(iv));
cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
keyspec, new IvParameterSpec(iv));
} catch (Exception e) {
cipher = null;
throw e;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/AES256CTR.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class AES256CTR implements Cipher {
public class AES256CTR implements com.jcraft.jsch.Cipher {
private static final int ivsize = 16;
private static final int bsize = 32;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand All @@ -60,9 +60,10 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {
}
try {
SecretKeySpec keyspec = new SecretKeySpec(key, "AES");
cipher = javax.crypto.Cipher.getInstance("AES/CTR/NoPadding");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), keyspec, new IvParameterSpec(iv));
cipher = Cipher.getInstance("AES/CTR/NoPadding");
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
keyspec, new IvParameterSpec(iv));
} catch (Exception e) {
cipher = null;
throw e;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/AESGCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import java.nio.ByteBuffer;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;

abstract class AESGCM implements Cipher {
abstract class AESGCM implements com.jcraft.jsch.Cipher {
// Actually the block size, not IV size
private static final int ivsize = 16;
private static final int tagsize = 16;
private javax.crypto.Cipher cipher;
private Cipher cipher;
private SecretKeySpec keyspec;
private int mode;
private ByteBuffer iv;
Expand Down Expand Up @@ -65,13 +65,13 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {
System.arraycopy(key, 0, tmp, 0, tmp.length);
key = tmp;
}
this.mode = ((mode == ENCRYPT_MODE) ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE);
this.mode =
((mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE) ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE);
this.iv = ByteBuffer.wrap(iv);
this.initcounter = this.iv.getLong(4);
try {
keyspec = new SecretKeySpec(key, "AES");
cipher = javax.crypto.Cipher.getInstance("AES/GCM/NoPadding");
cipher = Cipher.getInstance("AES/GCM/NoPadding");
cipher.init(this.mode, keyspec, new GCMParameterSpec(tagsize * 8, iv));
} catch (Exception e) {
cipher = null;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/ARCFOUR.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class ARCFOUR implements Cipher {
public class ARCFOUR implements com.jcraft.jsch.Cipher {
private static final int ivsize = 8;
private static final int bsize = 16;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand All @@ -54,10 +54,11 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {
}

try {
cipher = javax.crypto.Cipher.getInstance("RC4");
cipher = Cipher.getInstance("RC4");
SecretKeySpec _key = new SecretKeySpec(key, "RC4");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), _key);
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
_key);
} catch (Exception e) {
cipher = null;
throw e;
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/ARCFOUR128.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class ARCFOUR128 implements Cipher {
public class ARCFOUR128 implements com.jcraft.jsch.Cipher {
private static final int ivsize = 8;
private static final int bsize = 16;
private static final int skip = 1536;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand All @@ -54,10 +54,11 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {
key = tmp;
}
try {
cipher = javax.crypto.Cipher.getInstance("RC4");
cipher = Cipher.getInstance("RC4");
SecretKeySpec _key = new SecretKeySpec(key, "RC4");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), _key);
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
_key);
byte[] foo = new byte[1];
for (int i = 0; i < skip; i++) {
cipher.update(foo, 0, 1, foo, 0);
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/ARCFOUR256.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class ARCFOUR256 implements Cipher {
public class ARCFOUR256 implements com.jcraft.jsch.Cipher {
private static final int ivsize = 8;
private static final int bsize = 32;
private static final int skip = 1536;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand All @@ -54,10 +54,11 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {
key = tmp;
}
try {
cipher = javax.crypto.Cipher.getInstance("RC4");
cipher = Cipher.getInstance("RC4");
SecretKeySpec _key = new SecretKeySpec(key, "RC4");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), _key);
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
_key);
byte[] foo = new byte[1];
for (int i = 0; i < skip; i++) {
cipher.update(foo, 0, 1, foo, 0);
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/BlowfishCBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class BlowfishCBC implements Cipher {
public class BlowfishCBC implements com.jcraft.jsch.Cipher {
private static final int ivsize = 8;
private static final int bsize = 16;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand All @@ -60,9 +60,10 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {
}
try {
SecretKeySpec skeySpec = new SecretKeySpec(key, "Blowfish");
cipher = javax.crypto.Cipher.getInstance("Blowfish/CBC/NoPadding");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), skeySpec, new IvParameterSpec(iv));
cipher = Cipher.getInstance("Blowfish/CBC/NoPadding");
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
skeySpec, new IvParameterSpec(iv));
} catch (Exception e) {
throw e;
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jcraft/jsch/jce/BlowfishCTR.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

package com.jcraft.jsch.jce;

import com.jcraft.jsch.Cipher;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class BlowfishCTR implements Cipher {
public class BlowfishCTR implements com.jcraft.jsch.Cipher {
private static final int ivsize = 8;
private static final int bsize = 32;
private javax.crypto.Cipher cipher;
private Cipher cipher;

@Override
public int getIVSize() {
Expand All @@ -60,9 +60,10 @@ public void init(int mode, byte[] key, byte[] iv) throws Exception {
}
try {
SecretKeySpec skeySpec = new SecretKeySpec(key, "Blowfish");
cipher = javax.crypto.Cipher.getInstance("Blowfish/CTR/NoPadding");
cipher.init((mode == ENCRYPT_MODE ? javax.crypto.Cipher.ENCRYPT_MODE
: javax.crypto.Cipher.DECRYPT_MODE), skeySpec, new IvParameterSpec(iv));
cipher = Cipher.getInstance("Blowfish/CTR/NoPadding");
cipher.init(
(mode == com.jcraft.jsch.Cipher.ENCRYPT_MODE ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE),
skeySpec, new IvParameterSpec(iv));
} catch (Exception e) {
throw e;
}
Expand Down
Loading

0 comments on commit 8455767

Please sign in to comment.