0

我想通过android加密音频文件并通过后端sails js解密。我为此开发了程序,但我遇到了sails js 错误

error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt

在此处输入图像描述

这是我在android中加密音频文件的源代码

     final String ALGORITHM = "blowfish";
     String keyString = "DesireSecretKey";

    private void encrypt(String file) throws Exception {

        File extStore = Environment.getExternalStorageDirectory();
        File inputFile = new File(file);
        File encryptedFile = new 
        File(extStore+"/Movies/encryptAudio.amr");
        doCrypto(Cipher.ENCRYPT_MODE, inputFile, encryptedFile);
     }



     private  void doCrypto(int cipherMode, File inputFile,
                                 File outputFile) throws Exception {

        Key secretKey = new 
        SecretKeySpec(keyString.getBytes(),ALGORITHM);
        Cipher cipher = Cipher.getInstance(ALGORITHM);
        cipher.init(cipherMode, secretKey);

        FileInputStream inputStream = new FileInputStream(inputFile);
        byte[] inputBytes = new byte[(int) inputFile.length()];
        inputStream.read(inputBytes);

        byte[] outputBytes = cipher.doFinal(inputBytes);

        FileOutputStream outputStream = new 
        FileOutputStream(outputFile);
        outputStream.write(outputBytes);

        inputStream.close();
        outputStream.close();

    }

我通过以下命令在sails js后端安装了crypto、fs库 npm install crypto npm install fs

这是我在sails js中解密音频文件的源代码

   function decrypt() {
        var crypto = require('crypto'),
        algorithm = 'blowfish',
        password = 'DesireSecretKey';

        var fs = require('fs');

      // input file
        var r = fs.createReadStream(config.UPLOAD_FILES_PATH 
        +'/encryptAudio.amr');

     var decrypt = crypto.createDecipher(algorithm, password,"");

   // write file
    var w = fs.createWriteStream(config.AUDIO_PATH+'decryptAudio.amr');

   // start pipe
      r.pipe(decrypt).pipe(w);
  }

加密工作正常,我可以获得加密的音频文件。但问题是我无法通过sails js 获得解密的音频文件。你能确定问题吗?

4

1 回答 1

0

也许这个问题的答案可能会有所帮助,因为您正在使用 Java 的加密库,这应该可以指导您朝着正确的方向前进。 使用 Node.js Crypto 模块加密并使用 Java 解密(在 Android 应用程序中) 我会在评论部分提到这一点,但我没有足够的声誉点来评论。这与您想要实现的目标相反,但它仍然可以帮助您分析您的问题。

于 2017-09-26T19:07:03.790 回答