PgpCore 加密错误:“未指定加密方法”

问题描述 投票:0回答:0

尝试使用带有公钥的函数应用程序使用 EncryptStreamAsync 方法加密 Azure Blob 存储中的文件,我收到错误“未指定加密方法”。

                string publicKeyBase64 = System.Environment.GetEnvironmentVariable("PUBLICKEY");
                byte[] publicKeyBytes = Convert.FromBase64String(publicKeyBase64);
                string publicKey = Encoding.UTF8.GetString(publicKeyBytes);

                EncryptionKeys encryptionKeys = new EncryptionKeys(publicKey);

                PGP pgp = new PGP(encryptionKeys);

                BlobContainerClient inputContainer = new BlobContainerClient(connectionString, container);
                BlobContainerClient outputContainer = new BlobContainerClient(connectionString, container);

                Stream inputStream = await inputContainer.GetBlobClient(filePath).OpenReadAsync();
                Stream encryptedStream = new MemoryStream(); 

                await pgp.EncryptStreamAsync(inputStream, encryptedStream);
                encryptedStream.Seek(0, SeekOrigin.Begin);
                await outputContainer.UploadBlobAsync(filePath + ".pgp", encryptedStream);

知道是什么导致了这个错误吗?

发现Bouncy castles代码bouncycastle/openpgp/PGPEncryptedDataGenerator.java在methods.size()时出错< 0.

  private OutputStream open(
        OutputStream out,
        long length,
        byte[] buffer)
        throws IOException, PGPException, IllegalStateException
    {
        if (cOut != null)
        {
            throw new IllegalStateException("generator already in open state");
        }

        if (methods.size() == 0)
        {
            throw new IllegalStateException("no encryption methods specified");
        }
c# azure azure-functions pgp openpgp
© www.soinside.com 2019 - 2024. All rights reserved.