コード例 #1
0
    public void TestUploadEncryptedFile()
    {
        DownloadEncryptedFileSample downloadEncryptedFileSample = new DownloadEncryptedFileSample();
        UploadEncryptedFileSample   uploadEncryptedFileSample   = new UploadEncryptedFileSample();
        GenerateEncryptionKeySample generateEncryptionKeySample = new GenerateEncryptionKeySample();
        var key = generateEncryptionKeySample.GenerateEncryptionKey();

        // upload with key
        uploadEncryptedFileSample.UploadEncryptedFile(key, _fixture.BucketNameGeneric, _fixture.FilePath,
                                                      _fixture.Collect("HelloEncryptUpload.txt"));

        //download with key
        downloadEncryptedFileSample.DownloadEncryptedFile(key, _fixture.BucketNameGeneric, "HelloEncryptUpload.txt", "Hello-downloaded.txt");
        Assert.Equal(File.ReadAllText(_fixture.FilePath), File.ReadAllText("Hello-downloaded.txt"));
        File.Delete("Hello-downloaded.txt");
    }
コード例 #2
0
    public void ObjectCsekToCmek()
    {
        GenerateEncryptionKeySample generateEncryptionKeySample = new GenerateEncryptionKeySample();
        UploadEncryptedFileSample   uploadEncryptedFileSample   = new UploadEncryptedFileSample();
        GetMetadataSample           getMetadataSample           = new GetMetadataSample();
        ObjectCsekToCmekSample      objectCsekToCmekSample      = new ObjectCsekToCmekSample();

        // Upload with key
        var    objectName = "HelloObjectCsekToCmek.txt";
        string key        = generateEncryptionKeySample.GenerateEncryptionKey();

        uploadEncryptedFileSample.UploadEncryptedFile(key, _fixture.BucketNameRegional, _fixture.FilePath, _fixture.Collect(objectName));

        // Change key type to Cmek
        objectCsekToCmekSample.ObjectCsekToCmek(_fixture.ProjectId, _fixture.BucketNameRegional, objectName,
                                                key, _fixture.KmsKeyLocation, _fixture.KmsKeyRing, _fixture.KmsKeyName);

        // Verify Kms key Name
        var obj = getMetadataSample.GetMetadata(_fixture.BucketNameRegional, objectName);

        Assert.Contains(_fixture.KmsKeyName, obj.KmsKeyName);
    }
    public void ObjectRotateEncryptionKey()
    {
        GenerateEncryptionKeySample     generateEncryptionKeySample     = new GenerateEncryptionKeySample();
        UploadEncryptedFileSample       uploadEncryptedFileSample       = new UploadEncryptedFileSample();
        DownloadEncryptedFileSample     downloadEncryptedFileSample     = new DownloadEncryptedFileSample();
        GetMetadataSample               getMetadataSample               = new GetMetadataSample();
        ObjectRotateEncryptionKeySample objectRotateEncryptionKeySample = new ObjectRotateEncryptionKeySample();

        // Upload with key
        var    objectName = "HelloObjectRotateEncryptionKey.txt";
        string currentKey = generateEncryptionKeySample.GenerateEncryptionKey();
        string newKey     = generateEncryptionKeySample.GenerateEncryptionKey();

        uploadEncryptedFileSample.UploadEncryptedFile(currentKey, _fixture.BucketNameGeneric, _fixture.FilePath, _fixture.Collect(objectName));

        // Rotate key
        objectRotateEncryptionKeySample.ObjectRotateEncryptionKey(_fixture.BucketNameGeneric, objectName, currentKey, newKey);

        // Download with new key to verify key has changed
        downloadEncryptedFileSample.DownloadEncryptedFile(newKey, _fixture.BucketNameGeneric, objectName, "Downloaded-encrypted-object.txt");
        Assert.Equal(File.ReadAllText(_fixture.FilePath), File.ReadAllText("Downloaded-encrypted-object.txt"));
        File.Delete("Downloaded-encrypted-object.txt");
    }