Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CryptoCipher stackoverflow issue #8

Closed
BarisCirika opened this issue Nov 9, 2012 · 1 comment
Closed

CryptoCipher stackoverflow issue #8

BarisCirika opened this issue Nov 9, 2012 · 1 comment

Comments

@BarisCirika
Copy link

i add a pdf file with pdfpassword in that class it gives Stackoverflow issues to me.

at line 56

@Override
public void init(int mode, SecretKeySpec keySpec, IvParameterSpec Iv) {
    init(mode, keySpec, Iv); //why recursion?
}
@BarisCirika
Copy link
Author

i found the solution. you mean not

     init(mode, keySpec, Iv); //recursion

i just change all of init to cipher.init() like

     cipher.init(mode,keySpec,Iv);

All of the code here

package net.sf.andpdf.crypto;

import java.nio.ByteBuffer;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.ShortBufferException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class CryptoCipher extends Cipher {

javax.crypto.Cipher cipher;

public CryptoCipher(String ciphername) throws NoSuchAlgorithmException, NoSuchPaddingException {
    this.cipher = javax.crypto.Cipher.getInstance(ciphername);

}

@Override
public void doFinal(ByteBuffer nio, ByteBuffer decryptedBuf) throws IllegalBlockSizeException, ShortBufferException, BadPaddingException {
    cipher.doFinal(nio, decryptedBuf);
}

@Override
public byte[] doFinal(byte[] input) throws IllegalBlockSizeException, BadPaddingException {
    return cipher.doFinal(input);
}

@Override
public void doFinal(byte[] src, int from, int length, byte[] dest) throws IllegalBlockSizeException, ShortBufferException, BadPaddingException {
    cipher.doFinal(src, from, length, dest);
}

@Override
public void init(int mode, Key key) {
    try {
        cipher.init(mode, key);
    } catch (InvalidKeyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

@Override
public void init(int mode, SecretKey key) {
    try {
        cipher.init(mode, key);
    } catch (InvalidKeyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

@Override
public void init(int mode, SecretKeySpec keySpec) {
    try {
        cipher.init(mode, keySpec);
    } catch (InvalidKeyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

@Override
public void init(int mode, SecretKeySpec keySpec, IvParameterSpec Iv) {
    try {
        cipher.init(mode, keySpec, Iv);
    } catch (InvalidKeyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidAlgorithmParameterException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant