Converting Key to String and back to Key Java

前端 未结 1 1044
陌清茗
陌清茗 2020-12-16 06:12

so I\'m trying to convert a Key into a string so I can display it with System.out, and then I want to convert it back to a Key. I am able to convert it to a string with BASE

相关标签:
1条回答
  • 2020-12-16 06:46

    You never use your BASE64Decoder to un-base-64 your string.

    Replace this:

            Key key = new SecretKeySpec(keyString.getBytes(),0,keyString.getBytes().length, "DES");     
    

    with

            byte[] encodedKey = decoder.decodeBuffer(keyString);
            Key key = new SecretKeySpec(encodedKey,0,encodedKey.length, "DES");     
    
    0 讨论(0)
提交回复
热议问题