Carlos Vargas

Generating Secure Access Keys and Secret Keys for the HCP Platform with Microsoft .Net for C# and PowerShell

Blog Post created by Carlos Vargas Employee on Apr 18, 2016

The Hitachi Content Platform is a great Object Storage for your Datacenter. In order to use it programmatically you need to have a Access and Secret Key just like with every other object storage. This quick blog post will show you how to create those keys with PowerShell or C#

 

 

 

#################################################################

#################################################################

#                                                               #

# Name: Get-HS3AccessKey.ps1                                    #

# Author: Carlos Vargas                                         #

# Version : 1.0                                                 #

# Contact : carlos dot vargas at hds dot com                               #

# Note: Script to convert information for HS3 API for HCP       #

#                                                               #

#################################################################

#################################################################

 

# Intro

cls

Write-Host "HCP HS3 Access Key Convertion Tool"

Write-Host ""

Write-Host ""

 

# Function to Convert to Account name to Base64

function ConvertTo-Base64($string) {

   $bytes  = [System.Text.Encoding]::UTF8.GetBytes($string);

   $encoded = [System.Convert]::ToBase64String($bytes);

 

   return $encoded;

}

 

# Function to convert Password to MD5

Function Get-StringHash([String] $String,$HashName = "MD5")

{

$StringBuilder = New-Object System.Text.StringBuilder

[System.Security.Cryptography.HashAlgorithm]::Create($HashName).ComputeHash([System.Text.Encoding]::UTF8.GetBytes($String))|%{

[Void]$StringBuilder.Append($_.ToString("x2"))

}

$StringBuilder.ToString()

}

 

 

# Get Tenenat Account Name and Password

$accesskey = Read-host  "Type the HCP Tenant Account Name"

$SecretKey = Read-host  "Type the HCP Tenant Account Password" -AsSecureString

 

# Convert Secret to plain text

$BSTR = `

    [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecretKey)

$PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

 

# Send values to formulas

$aktemp =  ConvertTo-Base64($accesskey)

$sktemp =  Get-StringHash($PlainPassword)

 

# Output values

Write-Host ""

Write-host "The HS3 Access Key for $accesskey is: " $aktemp -ForegroundColor Yellow

Write-host "The HS3 Secret Key for $accesskey is: " $sktemp -ForegroundColor Green

Write-Host ""

Write-Host ""

 

pause

 

 

HCPS3Keys1.png

Outcomes