我们使用 BouncyCastle API 为客户端加密文件。当他尝试解密时,他收到了来自 PGP 的“仅供您查看”的消息。为什么?

2024-02-22

我们使用 Bouncy.Castle C# API 进行 PGP 加密。我绝不是 PGP 加密和各种可用选项方面的专家。

加密似乎运行良好,但是,当客户端尝试解密时,他说 PGP 不会输出到文件,而只会输出到屏幕,因为它被标记为“仅供您查看”。这是 --verbose 消息:

pgp --decrypt Client_FileExport_20110510_020011.zip.pgp
  Client_FileExport_20110511_132203.zip.pgp --info verbose

McAfee E-Business Server v8.5 - Full License
(c) 1991-2006 McAfee, Inc.  All Rights Reserved.

Setting temporary directory to C:\DOCUME~1\$963\LOCALS~1\Temp\
Decoding data....

event 1: initial
event 13: BeginLex
event 8: Analyze
File is encrypted.  event 9: Recipients
Secret key is required to read it.
Key for user ID "Client_RSAv4_Key <[email protected] /cdn-cgi/l/email-protection>"
event 6: Passphrase
You need a pass phrase to unlock your secret key.

Enter pass phrase:

event 23: Decryption

symmetric cipher used: CAST5
event 11: Output options
typecode: 0062
for your eyes only


This message is marked "For your eyes only".  Display now (Y/n)?

我不知道如何进行调试。有人知道吗?

这是我们用来加密数据的通用代码。在这种情况下,我们不会签署文档,因此可以忽略该部分代码。

private void EncryptImpl(Stream inputStream, Stream outputStream, bool signOutput)
    {
        const int BUFFER_SIZE = 1 << 16; // should always be power of 2
        bool armor = true;
        bool withIntegrityCheck = true;

        if (armor)
            outputStream = new ArmoredOutputStream(outputStream);

        var encKey = PgpHelper.ReadPublicKey(this.EncryptionPublicKey);

        // Init encrypted data generator
        PgpEncryptedDataGenerator encryptedDataGenerator =
            new PgpEncryptedDataGenerator(SymmetricKeyAlgorithmTag.Cast5, withIntegrityCheck, new SecureRandom());
        encryptedDataGenerator.AddMethod(encKey);
        Stream encryptedOut = encryptedDataGenerator.Open(outputStream, new byte[BUFFER_SIZE]);

        // Init compression
        PgpCompressedDataGenerator compressedDataGenerator = new PgpCompressedDataGenerator(CompressionAlgorithmTag.Zip);
        Stream compressedOut = compressedDataGenerator.Open(encryptedOut);

        PgpSignatureGenerator signatureGenerator = null;
        if (signOutput)
        {
            // Init signature
            var pgpSecKey = PgpHelper.ReadSecretKey(this.OrigamiSecretKey);
            PgpPrivateKey pgpPrivKey = pgpSecKey.ExtractPrivateKey(this.PassPhrase.ToCharArray());
            signatureGenerator = new PgpSignatureGenerator(pgpSecKey.PublicKey.Algorithm, HashAlgorithmTag.Sha1);
            signatureGenerator.InitSign(PgpSignature.BinaryDocument, pgpPrivKey);
            foreach (string userId in pgpSecKey.PublicKey.GetUserIds())
            {
                PgpSignatureSubpacketGenerator spGen = new PgpSignatureSubpacketGenerator();
                spGen.SetSignerUserId(false, userId);
                signatureGenerator.SetHashedSubpackets(spGen.Generate());
                // Just the first one!
                break;
            }
            signatureGenerator.GenerateOnePassVersion(false).Encode(compressedOut);
        }

        // Create the Literal Data generator output stream
        PgpLiteralDataGenerator literalDataGenerator = new PgpLiteralDataGenerator();

        // TODO: Use lastwritetime from source file
        Stream literalOut = literalDataGenerator.Open(compressedOut, PgpLiteralData.Binary,
            PgpLiteralDataGenerator.Console, DateTime.Now, new byte[BUFFER_SIZE]);

        // Open the input file
        byte[] buf = new byte[BUFFER_SIZE];
        int len;
        while ((len = inputStream.Read(buf, 0, buf.Length)) > 0)
        {
            literalOut.Write(buf, 0, len);

            if (signOutput)
                signatureGenerator.Update(buf, 0, len);
        }

        literalOut.Close();
        literalDataGenerator.Close();

        if (signOutput)
            signatureGenerator.Generate().Encode(compressedOut);

        compressedOut.Close();
        compressedDataGenerator.Close();
        encryptedOut.Close();
        encryptedDataGenerator.Close();
        inputStream.Close();

        if (armor)
            outputStream.Close();
    }

我猜测是 PgpLiteralDataGenerator.Console 导致它仅显示在客户端计算机的控制台中。

Stream literalOut = literalDataGenerator.Open(
    compressedOut, 
    PgpLiteralData.Binary,             
    PgpLiteralDataGenerator.Console,
    DateTime.Now, 
    new byte[BUFFER_SIZE]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我们使用 BouncyCastle API 为客户端加密文件。当他尝试解密时,他收到了来自 PGP 的“仅供您查看”的消息。为什么? 的相关文章

  • 检查两个数是否是彼此的排列?

    给定两个数字 a b 使得 1 例如 123 是 312 的有效排列 我也不想对数字中的数字进行排序 如果您指的是数字的字符 例如 1927 和 9721 则 至少 有几种方法 如果允许排序 一种方法是简单地sprintf将它们放入两个缓冲
  • 如何使 Windows 窗体的关闭按钮不关闭窗体但使其不可见?

    该表单有一个 NotifyIcon 对象 当用户单击 关闭 按钮时 我希望表单不关闭而是变得不可见 然后 如果用户想再次查看该表单 可以双击系统托盘中的图标 如果用户想关闭表单 可以右键单击该图标并选择 关闭 有人可以告诉我如何使关闭按钮不
  • C# 和 Javascript SHA256 哈希的代码示例

    我有一个在服务器端运行的 C 算法 它对 Base64 编码的字符串进行哈希处理 byte salt Convert FromBase64String serverSalt Step 1 SHA256Managed sha256 new S
  • pthread_cond_timedwait() 和 pthread_cond_broadcast() 解释

    因此 我在堆栈溢出和其他资源上进行了大量搜索 但我无法理解有关上述函数的一些内容 具体来说 1 当pthread cond timedwait 因为定时器值用完而返回时 它如何自动重新获取互斥锁 互斥锁可能被锁定在其他地方 例如 在生产者
  • C++ 子字符串返回错误结果

    我有这个字符串 std string date 20121020 我正在做 std cout lt lt Date lt lt date lt lt n std cout lt lt Year lt lt date substr 0 4 l
  • 实时服务器上的 woff 字体 MIME 类型错误

    我有一个 asp net MVC 4 网站 我在其中使用 woff 字体 在 VS IIS 上运行时一切正常 然而 当我将 pate 上传到 1and1 托管 实时服务器 时 我得到以下信息 网络错误 404 未找到 http www co
  • 当 contains() 工作正常时,xpath 函数ends-with() 工作时出现问题

    我正在尝试获取具有以特定 id 结尾的属性的标签 like span 我想获取 id 以 国家 地区 结尾的跨度我尝试以下xpath span ends with id Country 但我得到以下异常 需要命名空间管理器或 XsltCon
  • 为什么#pragma optimize("", off)

    我正在审查一个 C MFC 项目 在某些文件的开头有这样一行 pragma optimize off 我知道这会关闭所有以下功能的优化 但这样做的动机通常是什么 我专门使用它来在一组特定代码中获得更好的调试信息 并在优化的情况下编译应用程序
  • 在 Visual Studio 2008 上设置预调试事件

    我想在 Visual Studio 中开始调试程序之前运行一个任务 我每次调试程序时都需要运行此任务 因此构建后事件还不够好 我查看了设置的 调试 选项卡 但没有这样的选项 有什么办法可以做到这一点吗 你唯一可以尝试的 IMO 就是尝试Co
  • C#:如何防止主窗体过早显示

    在我的 main 方法中 我像往常一样启动主窗体 Application EnableVisualStyles Application SetCompatibleTextRenderingDefault false Application
  • Qt moc 在头文件中实现?

    是否可以告诉 Qt MOC 我想声明该类并在单个文件中实现它 而不是将它们拆分为 h 和 cpp 文件 如果要在 cpp 文件中声明并实现 QObject 子类 则必须手动包含 moc 文件 例如 文件main cpp struct Sub
  • Web API - 访问 DbContext 类中的 HttpContext

    在我的 C Web API 应用程序中 我添加了CreatedDate and CreatedBy所有表中的列 现在 每当在任何表中添加新记录时 我想填充这些列 为此目的我已经覆盖SaveChanges and SaveChangesAsy
  • for循环中计数器变量的范围是多少?

    我在 Visual Studio 2008 中收到以下错误 Error 1 A local variable named i cannot be declared in this scope because it would give a
  • 如何将单个 char 转换为 int [重复]

    这个问题在这里已经有答案了 我有一串数字 例如 123456789 我需要提取它们中的每一个以在计算中使用它们 我当然可以通过索引访问每个字符 但是如何将其转换为 int 我研究过 atoi 但它需要一个字符串作为参数 因此 我必须将每个字
  • clang 实例化后静态成员初始化

    这样的代码可以用 GCC 编译 但 clang 3 5 失败 include
  • 当操作繁忙时,表单不执行任何操作(冻结)

    我有一个使用 C 的 WinForms 应用程序 我尝试从文件中读取一些数据并将其插入数据表中 当此操作很忙时 我的表单冻结并且无法移动它 有谁知道我该如何解决这个问题 这可能是因为您在 UI 线程上执行了操作 将文件和数据库操作移至另一个
  • 控制到达非 void 函数末尾 -wreturn-type

    这是查找四个数字中的最大值的代码 include
  • 如何让Gtk+窗口背景透明?

    我想让 Gtk 窗口的背景透明 以便只有窗口中的小部件可见 我找到了一些教程 http mikehearn wordpress com 2006 03 26 gtk windows with alpha channels https web
  • 为什么 C# Math.Ceiling 向下舍入?

    我今天过得很艰难 但有些事情不太对劲 在我的 C 代码中 我有这样的内容 Math Ceiling decimal this TotalRecordCount this PageSize Where int TotalRecordCount
  • 防止索引超出范围错误

    我想编写对某些条件的检查 而不必使用 try catch 并且我想避免出现 Index Out of Range 错误的可能性 if array Element 0 Object Length gt 0 array Element 1 Ob

随机推荐