コード例 #1
0
    public void EncryptsData()
    {
        var data = "testing1234";

        // Run the sample code.
        var signature = _sample.SignMac(
            projectId: _fixture.ProjectId, locationId: _fixture.LocationId, keyRingId: _fixture.KeyRingId, keyId: _fixture.MacKeyId, keyVersionId: "1",
            data: data);

        // Verify the signature.
        KeyManagementServiceClient client         = KeyManagementServiceClient.Create();
        CryptoKeyVersionName       keyVersionName = new CryptoKeyVersionName(_fixture.ProjectId, _fixture.LocationId, _fixture.KeyRingId, _fixture.MacKeyId, "1");

        MacVerifyResponse result = client.MacVerify(keyVersionName, ByteString.CopyFromUtf8(data), ByteString.CopyFrom(signature));

        Assert.True(result.Success);
    }
コード例 #2
0
    public bool VerifyMac(
        string projectId = "my-project", string locationId = "us-east1", string keyRingId = "my-key-ring", string keyId = "my-key", string keyVersionId = "123",
        string data      = "my data",
        byte[] signature = null)
    {
        // Build the key version name.
        CryptoKeyVersionName keyVersionName = new CryptoKeyVersionName(projectId, locationId, keyRingId, keyId, keyVersionId);

        // Create the client.
        KeyManagementServiceClient client = KeyManagementServiceClient.Create();

        // Convert the data and signatures into ByteStrings.
        ByteString dataByteString      = ByteString.CopyFromUtf8(data);
        ByteString signatureByteString = ByteString.CopyFrom(signature);

        // Verify the signature.
        MacVerifyResponse result = client.MacVerify(keyVersionName, dataByteString, signatureByteString);

        // Return the result.
        return(result.Success);
    }