加密PBEWithMD5AndDES在j2me [英] encrypt PBEWithMD5AndDES in j2me

查看:165
本文介绍了加密PBEWithMD5AndDES在j2me的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让这段代码在j2me
上工作(它正在开发一个java程序)
但尚未在j2me中

  public static String generate(String plaintext,String passphase)throws异常{
try {
PBEKeySpec pbeKeySpec = new PBEKeySpec(passphase.toCharArray());
PBEParameterSpec pbeParamSpec;
SecretKeyFactory keyFac;
// Salt
byte [] salt = {(byte)0xc8,(byte)0x73,(byte)0x61,(byte)0x1d,(byte)0x1a,(byte)0xf2,(byte) 0xa8,(byte)0x99};
//迭代计数
int count = 20;
//创建PBE参数集
pbeParamSpec = new PBEParameterSpec(salt,count);
keyFac = SecretKeyFactory.getInstance(PBEWithMD5AndDES);
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
//创建PBE密码
密码pbeCipher = Cipher.getInstance(PBEWithMD5AndDES);
//用键和参数初始化PBE密码
pbeCipher.init(Cipher.ENCRYPT_MODE,pbeKey,pbeParamSpec);
//我们的cleartext
byte [] cleartext = plaintext.getBytes();
//加密明文
byte [] ciphertext = pbeCipher.doFinal(cleartext);
返回密文;
} catch(Exception ex){
throw new Exception(ex.getMessage());
}
}

我发现这个lib
http://www.bouncycastle.org/java.html


$ b $重要的是,我找到一个可以使用PBEWithMD5AndDES加密的j2me的方法



任何人都知道解决方案?



编辑添加额外的信息



当我尝试将以上代码添加到移动项目
以下类是不确认(不包括在j2me中)

  PBEKeySpec 
PBEParameterSpec
SecretKeyFactory

所以我需要一个允许我使用PBEWithMD5AndDES
对纯文本进行编码的包,任何人都知道这样一个与j2me兼容的包? / p>
解决方案

很多可能会出错应用原语时,您应该使用 Jasyp t


i'm triing to get this code to work on j2me (it is working a java program) but not yet in j2me

    public static String generate(String plaintext, String passphase) throws Exception {
        try {
            PBEKeySpec pbeKeySpec = new PBEKeySpec(passphase.toCharArray());
            PBEParameterSpec pbeParamSpec;
            SecretKeyFactory keyFac;
            // Salt
            byte[] salt = {(byte) 0xc8, (byte) 0x73, (byte) 0x61, (byte) 0x1d, (byte) 0x1a, (byte) 0xf2, (byte) 0xa8, (byte) 0x99};
            // Iteration count
            int count = 20;
            // Create PBE parameter set
            pbeParamSpec = new PBEParameterSpec(salt, count);
            keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
            SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
            // Create PBE Cipher
            Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
            // Initialize PBE Cipher with key and parameters
            pbeCipher.init(Cipher.ENCRYPT_MODE, pbeKey, pbeParamSpec);
            // Our cleartext
            byte[] cleartext = plaintext.getBytes();
            // Encrypt the cleartext
            byte[] ciphertext = pbeCipher.doFinal(cleartext);
            return ciphertext;
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }
    }

i found this lib http://www.bouncycastle.org/java.html

the important thing is that i find a method for j2me that can encrypt using PBEWithMD5AndDES

anyone know the solution?

edit adding extra info

when i try to add the above code to a mobile project following classes are not recognized (not included in j2me)

    PBEKeySpec
    PBEParameterSpec
    SecretKeyFactory

so i need a package that allows me to encode plain text using PBEWithMD5AndDES anyone know such a package compatible with j2me?

thx for the replies so far

解决方案

A lot can go wrong when applying a primitive, you should use Jasypt.

这篇关于加密PBEWithMD5AndDES在j2me的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆