예제 #1
0
        private void verify(RopBind rop)
        {
            int alt = rop.tagging();

            try {
                // initialize
                RopSession ses = rop.create_session(RopBind.KEYSTORE_GPG, RopBind.KEYSTORE_GPG);

                // we do not load any keys here since we'll use key provider
                ses.set_key_provider(this, null);

                String    err_desc = null;
                RopOutput output   = null;
                try {
                    // create file input and memory output objects for the signed message
                    // and verified message
                    err_desc = "Failed to open file 'signed.asc'. Did you run the sign example?";
                    RopInput input = rop.create_input("signed.asc");

                    err_desc = "Failed to create output object";
                    output   = rop.create_output(0);

                    err_desc = "Failed to create verification context";
                    RopOpVerify verify = ses.op_verify_create(input, output);

                    err_desc = "Failed to execute verification operation";
                    verify.execute();

                    // now check signatures and get some info about them
                    err_desc = "Failed to get signature count";
                    int sigcount = verify.signature_count();

                    for (int idx = 0; idx < sigcount; idx++)
                    {
                        rop.tagging();

                        err_desc = String.Format("Failed to get signature {0}", idx);
                        RopVeriSignature sig = verify.get_signature_at(idx);

                        err_desc = String.Format("failed to get signature's {0} key", idx);
                        RopKey key = sig.get_key();

                        err_desc = String.Format("failed to get key id {0}", idx);

                        Console.WriteLine(String.Format("Status for signature from key {0} : {1}", key.keyid(), sig.status()));
                        rop.drop();
                    }
                } catch (RopError ex) {
                    Console.WriteLine(err_desc);
                    throw ex;
                }

                // get the verified message from the output structure
                RopData buf = output.memory_get_buf(false);
                Console.WriteLine(String.Format("Verified message: {0}", buf.getString()));
            } finally {
                rop.drop_from(alt);
            }
        }
예제 #2
0
파일: Decrypt.cs 프로젝트: joke325/Dotrop
        private void decrypt(RopBind rop, bool usekeys)
        {
            int alt = rop.tagging();

            try {
                // initialize FFI object
                RopSession ses = rop.create_session(RopBind.KEYSTORE_GPG, RopBind.KEYSTORE_GPG);

                // check whether we want to use key or password for decryption
                if (usekeys)
                {
                    RopInput keyfile = null;
                    try {
                        // load secret keyring, as it is required for public-key decryption. However, you may
                        // need to load public keyring as well to validate key's signatures.
                        keyfile = rop.create_input("secring.pgp");
                        // we may use secret=True and public=True as well
                        ses.load_keys_secret(RopBind.KEYSTORE_GPG, keyfile);
                    } catch (RopError ex) {
                        Console.WriteLine("Failed to read secring");
                        throw ex;
                    } finally {
                        rop.drop(keyfile);
                    }
                }

                // set the password provider
                ses.set_pass_provider(this, null);
                String buf = null;
                try {
                    // create file input and memory output objects for the encrypted message and decrypted
                    // message
                    RopInput  input  = rop.create_input("encrypted.asc");
                    RopOutput output = rop.create_output(0);
                    ses.decrypt(input, output);
                    // get the decrypted message from the output structure
                    buf = output.memory_get_buf(false).getString();
                } catch (RopError ex) {
                    Console.WriteLine("Public-key decryption failed");
                    throw ex;
                }

                Console.WriteLine(String.Format("Decrypted message ({0}):\n{1}\n", usekeys? "with key" : "with password", buf));
                Decrypt.message = buf;
            } finally {
                rop.drop_from(alt);
            }
        }
예제 #3
0
파일: Generate.cs 프로젝트: joke325/Dotrop
        /**
         * This simple helper function just prints armored key, searched by userid, to stdout.
         */
        private void print_key(RopBind rop, RopSession ses, string uid, bool secret)
        {
            // you may search for the key via userid, keyid, fingerprint, grip
            RopKey key = ses.locate_key("userid", uid);
            // create in-memory output structure to later use buffer
            RopOutput keydata = rop.create_output(0);

            try {
                if (secret)
                {
                    key.export_secret(keydata, true, true);
                }
                else
                {
                    key.export_public(keydata, true, true);
                }
                // get key's contents from the output structure
                RopData buf = keydata.memory_get_buf(false);
                Console.WriteLine(buf.getString());
            } finally {
                rop.drop(keydata);
            }
        }