bouncycastle的CAST5的等效密码是多少?

时间:2018-09-14 08:50:36

标签: javascript java node.js bouncycastle

我正在尝试在Java(使用Bouncy Castle)和Node.js中执行相同的加密操作,但是我不知道哪种算法可以与Node JavaScript(加密JavaScript库)一起使用,结果相同。

下面是我尝试的实现?

Java代码

ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(
            PGPCompressedDataGenerator.ZIP);
    OutputStream cos = comData.open(bOut); // open it with the final
    // destination
    PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator();

    // we want to generate compressed data. This might be a user option
    // later,
    // in which case we would pass in bOut.
    OutputStream pOut = lData.open(cos, // the compressed output stream
            PGPLiteralData.BINARY, fileName, // "filename" to store
            clearData.length, // length of clear data
            new Date() // current time
    );
    pOut.write(clearData);

    lData.close();
    comData.close();

    Provider provider = new BouncyCastleProvider();
    PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(
        new JcePGPDataEncryptorBuilder( PGPEncryptedData.CAST5)
        .setWithIntegrityPacket( withIntegrityCheck )
        .setSecureRandom(new SecureRandom() )
        .setProvider(provider) );        

    cPk.addMethod( new JcePublicKeyKeyEncryptionMethodGenerator( encKey ).setProvider( provider ) );

    byte[] bytes = bOut.toByteArray();

    OutputStream cOut = cPk.open(out, bytes.length);

    cOut.write(bytes); // obtain the actual bytes from the compressed stream

    cOut.close();

    out.close();

我无法从下面的列表中知道使用哪种算法才能获得相同的结果,因此请使用哪种算法来获得相同的结果: cast-cbc,cast5-cbc,cast5-cfb,cast5-ecb,cast5-ofb。

0 个答案:

没有答案