Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6101215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:28:29+00:00 2026-05-23T13:28:29+00:00

Really a buggy question , hee is the code: import java.io.IOException; import java.security.*; import

  • 0

Really a buggy question , hee is the code:

import java.io.IOException;
import java.security.*;

import javax.crypto.*;
import javax.crypto.spec.*;

public class Encryption {
public static final int a = 0x9F224;
public static final int b = 0x98C36;
public static final int c = 0x776a2;
public static final int d = 0x87667;

private String preMaster;
IvParameterSpec ivSpec = new IvParameterSpec(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x01 });
private byte[] text;
private SecretKey secret;
private byte[] sKey;
protected SecretKey passwordKey;
protected PBEParameterSpec paramSpec;
public static final String ENCYT_ALGORITHM = "AES/CBC/PKCS7Padding";
public static final String KEY_ALGORITHM = "PBEWITHSHA256AND256BITAES-CBC-BC" ;
//BENCYT_ALGORITHMSE64Encoder encod = new BENCYT_ALGORITHMSE64Encoder();
//BENCYT_ALGORITHMSE64Decoder decod = new BENCYT_ALGORITHMSE64Decoder();

public Encryption(String preMaster,String text,int x){      
    this.preMaster=preMaster;       
    this.text=Encoder.decode(text.toCharArray());
    try {

        KeyGenerator kg = KeyGenerator.getInstance("AES");
        kg.init(256);
        secret = kg.generateKey();
    } catch (Exception e) {
        // TODO ENCYT_ALGORITHMuto-generated catch block
        e.printStackTrace();
    }
}

public Encryption(String key,String text){
    try {
        this.text = Encoder.decode(text.toCharArray());
        this.sKey = Encoder.decode(key.toCharArray());
    } catch (Exception e) {
        e.printStackTrace();
    }

}   

public String preMaster() {

    byte[] keys = null;
    keys = preMaster.getBytes();
    int x = -1;
    int process = 0;
    while (x < keys.length - 2) {
        x++;
        switch (x) {
        case 1:
            process = keys[x + 1] | a ^ c & (d | keys[x] % a);
        case 2:
            process += a | (keys[x] ^ c) & d;
        case 3:
            process += keys[x] ^ (keys[x + 1] / a) % d ^ b;
        default:
            process += keys[x + 1] / (keys[x] ^ c | d);
        }
    }

    byte[] xs = new byte[] { (byte) (process >>> 24),
            (byte) (process >> 16 & 0xff), (byte) (process >> 8 & 0xff),
            (byte) (process & 0xff) };
    preMaster = new String(xs);
    KeyGenerators key = new KeyGenerators(preMaster);
    String toMaster = key.calculateSecurityHash("MD5")
            + key.calculateSecurityHash("MD2")
            + key.calculateSecurityHash("SHA-512");


    return toMaster;
}

public String keyWrapper(){
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); 
    Key SharedKey = secret;
    String key = null;
    char[] preMaster = this.preMaster().toCharArray();
    try {

        byte[]salt={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; 
        paramSpec = new PBEParameterSpec(salt,20);
        PBEKeySpec keySpec = new PBEKeySpec(preMaster);
        SecretKeyFactory factory = SecretKeyFactory.getInstance(KEY_ALGORITHM);
        passwordKey = factory.generateSecret(keySpec);
        Cipher c = Cipher.getInstance(KEY_ALGORITHM);
        c.init(Cipher.WRAP_MODE, passwordKey, paramSpec);
        byte[] wrappedKey = c.wrap(SharedKey);
        key=Encoder.encode(wrappedKey);
    }catch(Exception e){
        e.printStackTrace();
    }
    return key;
}

public Key KeyUnwrapper(){
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); 
    byte[] wrappedKey = sKey;
    Key unWrapped = null;
    try{
        Cipher c = Cipher.getInstance(KEY_ALGORITHM,"BC");
        c.init(Cipher.UNWRAP_MODE, passwordKey, paramSpec);
        unWrapped = c.unwrap(wrappedKey, ENCYT_ALGORITHM, Cipher.SECRET_KEY);

    }catch(Exception e){
        e.printStackTrace();
    }
    return unWrapped;
}
public String encrypt(){
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); 

    SecretKey key = secret;
    String result=null;
    try{
        Cipher cipher = Cipher.getInstance(ENCYT_ALGORITHM);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        result =Encoder.encode(cipher.doFinal(text));
    }catch(Exception e){
        e.printStackTrace();
    }
    return result;
}



public String decrypt(){
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); 
    String result = null;
    SecretKey key = (SecretKey) KeyUnwrapper();
    try{
        Cipher cipher = Cipher.getInstance(ENCYT_ALGORITHM, "BC");
        cipher.init(Cipher.DECRYPT_MODE, key);
        result =  Encoder.encode(cipher.doFinal(text));
    }catch(Exception e){
        e.printStackTrace();
    }
    return result;
}

public static void main(String[] args) throws IOException{
    Encryption en = new Encryption("123456","Hello World",0);
    String enText = en.encrypt();
    String key = en.keyWrapper();
    System.out.println(key);
    System.out.println(enText);
    Encryption de = new Encryption(key,enText);
    String plainText = de.decrypt();
    System.out.println(plainText);
}

And , this is the result … i tried all the combinations i can, but none of them works ..

F63DE3EE8CEECF4DF76836CA6D69A3903BD87B5726656C54C1C8EC30B6653B2C0E5C7672BE3CF4BE7B2DC7AC5D07DEA0
F1C8D92E5F74019C569D54D70045ADD6
java.lang.NullPointerException
at org.bouncycastle.jce.provider.JCEBlockCipher.engineInit(Unknown Source)
at javax.crypto.Cipher.init(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at fiador.authentication.util.Encryption.KeyUnwrapper(Encryption.java:114)
at fiador.authentication.util.Encryption.decrypt(Encryption.java:142)
at fiador.authentication.util.Encryption.main(Encryption.java:160) 
java.lang.NullPointerException
at org.bouncycastle.jce.provider.JCEBlockCipher.engineInit(Unknown Source)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.a(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at javax.crypto.Cipher.init(DashoA13*..)
at fiador.authentication.util.Encryption.decrypt(Encryption.java:145)
at fiador.authentication.util.Encryption.main(Encryption.java:160)

null

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:28:29+00:00Added an answer on May 23, 2026 at 1:28 pm

    The first NullPointerException occurs inside this method call (in the KeyUnwrapper method):

    c.init(Cipher.UNWRAP_MODE, passwordKey, paramSpec);
    

    Have a look: Could one of these arguments be null?

    Looking at the code, it seems like passwordKey is only assigned to in keyWrapper, but this is not called on this instance of your class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really simple question - how do I do a search to find all records
Really stuck on trying to write code to unzip a file or directory on
Really my question has more to do with the server-side scrubbing of html that's
I really enjoyed Jeff's post on Spartan Programming . I agree that code like
Really dumb question but, for instance, given: var $foo = $('<div>bar</div>'); How would I
Really confused with this one. I am selecting an 'a' element by its class
Really simple question. I trying to test a Restful webservice that I am developing,
Really my question is, if I were to use a nested data structure in
Really quick question.. Does Linq2NHibernate always create a left join to retrieve relationships? Is
I'm completely tired of all the buggy code I've been writing for all this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.