Ejemplo n.º 1
0
  byte[] getEncodedKey(org.mozilla.jss.crypto.PrivateKey pkey) throws Exception {

    CryptoManager cm = CryptoManager.getInstance();
    CryptoToken token = cm.getInternalKeyStorageToken();

    KeyGenerator kg = token.getKeyGenerator(KeyGenAlgorithm.DES3);
    SymmetricKey sk = kg.generate();

    KeyWrapper wrapper = token.getKeyWrapper(KeyWrapAlgorithm.DES3_CBC_PAD);
    byte iv[] = {0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1};
    IVParameterSpec param = new IVParameterSpec(iv);
    wrapper.initWrap(sk, param);
    byte[] enckey = wrapper.wrap(pkey);

    Cipher c = token.getCipherContext(EncryptionAlgorithm.DES3_CBC_PAD);
    c.initDecrypt(sk, param);
    return c.doFinal(enckey);
  }