bouncycastle connect to android studio

|▌冷眼眸甩不掉的悲伤 提交于 2020-05-31 02:02:38

问题


Good time of day, I need to somehow connect the bouncycastle library to android studio. How can this be done? I've never dealt with one before. Here is the code for which I need this library:

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        byte[] input = "www.javaCODEgeeks.com".getBytes();
        byte[] keyBytes = new byte[]{0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd,


                (byte) 0xef};



        byte[] ivBytes = new byte[]{0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};


        SecretKeySpec pKey = new SecretKeySpec(keyBytes, "DES");

        IvParameterSpec ivectorSpecv = new IvParameterSpec(ivBytes);

        Cipher c = Cipher.getInstance("DES/CBC/PKCS7Padding", "BC");


        System.out.println("input : " + new String(input));


        // encryption pass


        c.init(Cipher.ENCRYPT_MODE, pKey, ivectorSpecv);


        byte[] encr = new byte;


        int ctLen = c.update(input, 0, input.length, encr, 0);


        ctLen += c.doFinal(encr, ctLen);


        System.out.println("cipher: " + new String(encr).getBytes("UTF-8").toString() + " bytes: " + ctLen);
        c.init(Cipher.DECRYPT_MODE, pKey, ivectorSpecv);
        byte[] decrpt = new byte;
        int ptLen = c.update(encr, 0, ctLen, decrpt, 0);
        ptLen += c.doFinal(decrpt, ptLen);
        System.out.println("plain : " + new String(decrpt) + " bytes: " + ptLen);

Thanks in advance for your help)


回答1:


In your module (app-level) Gradle file (usually app/build.gradle) add this dependency

implementation 'org.bouncycastle:bcpkix-jdk15on:1.56'


来源:https://stackoverflow.com/questions/55187472/bouncycastle-connect-to-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!