Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. Walmart Partner API Authentication (Generate a Signature for a Request) Generate RSA Key and return Base64 PKCS8 Private Key; Convert RSA Private Key to Public Key; Get RSA Private Key in JWK Format (JSON Web Key) Get ECC Private Key in JWK Format (JSON Web Key) Get RSA Public Key in JWK Format (JSON Web Key) Get ECC Public Key in JWK Format.
Generate SSH RSA Private/Public Key pair with Golang - gist:8f9b8a4f31573f428f29ec0e884e6673. Package crypto/ecdsa GenerateKey generates a public and private key. //fmt.Printf('CRTValues: Exp%s Coeff%s R%s ', CRTVal2.Exp.String, CRTVal2.Coeff.String, CRTVal2.R.String). Osstatus key generation failed 25293.
Chilkat • HOME • Android™ • Classic ASP • C • C++ • C# • Mono C# • .NET Core C# • C# UWP/WinRT • DataFlex • Delphi ActiveX • Delphi DLL • Visual FoxPro • Java • Lianja • MFC • Objective-C • Perl • PHP ActiveX • PHP Extension • PowerBuilder • PowerShell • PureBasic • CkPython • Chilkat2-Python • Ruby • SQL Server • Swift 2 • Swift 3/4 • Tcl • Unicode C • Unicode C++ • Visual Basic 6.0 • VB.NET • VB.NET UWP/WinRT • VBScript • Xojo Plugin • Node.js • Excel • Go
| Demonstrates how to generate a new RSA key and a Certificate Signing Request (CSR). Note: This example requires Chilkat v9.5.0.65 or greater.
|
© 2000-2020 Chilkat Software, Inc. All Rights Reserved.
PermalinkGitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign uppackage main |
import ( |
'crypto' |
'crypto/rand' |
'crypto/rsa' |
'crypto/sha256' |
'fmt' |
'os' |
) |
funcmain() { |
// Generate RSA Keys |
miryanPrivateKey, err:=rsa.GenerateKey(rand.Reader, 2048) |
iferr!=nil { |
fmt.Println(err.Error) |
os.Exit(1) |
} |
miryanPublicKey:=&miryanPrivateKey.PublicKey |
raulPrivateKey, err:=rsa.GenerateKey(rand.Reader, 2048) |
iferr!=nil { |
fmt.Println(err.Error) |
os.Exit(1) |
} |
raulPublicKey:=&raulPrivateKey.PublicKey |
fmt.Println('Private Key : ', miryanPrivateKey) |
fmt.Println('Public key ', miryanPublicKey) |
fmt.Println('Private Key : ', raulPrivateKey) |
fmt.Println('Public key ', raulPublicKey) |
//Encrypt Miryan Message |
message:= []byte('the code must be like a piece of music') |
label:= []byte(') |
hash:=sha256.New() |
ciphertext, err:=rsa.EncryptOAEP(hash, rand.Reader, raulPublicKey, message, label) |
iferr!=nil { |
fmt.Println(err) |
os.Exit(1) |
} |
fmt.Printf('OAEP encrypted [%s] to n[%x]n', string(message), ciphertext) |
fmt.Println() |
// Message - Signature |
varopts rsa.PSSOptions |
opts.SaltLength=rsa.PSSSaltLengthAuto// for simple example |
PSSmessage:=message |
newhash:=crypto.SHA256 |
pssh:=newhash.New() |
pssh.Write(PSSmessage) |
hashed:=pssh.Sum(nil) |
signature, err:=rsa.SignPSS(rand.Reader, miryanPrivateKey, newhash, hashed, &opts) |
iferr!=nil { |
fmt.Println(err) |
os.Exit(1) |
} |
fmt.Printf('PSS Signature : %xn', signature) |
// Decrypt Message |
plainText, err:=rsa.DecryptOAEP(hash, rand.Reader, raulPrivateKey, ciphertext, label) |
iferr!=nil { |
fmt.Println(err) |
os.Exit(1) |
} |
fmt.Printf('OAEP decrypted [%x] to n[%s]n', ciphertext, plainText) |
//Verify Signature |
err=rsa.VerifyPSS(miryanPublicKey, newhash, hashed, signature, &opts) |
iferr!=nil { |
fmt.Println('Who are U? Verify Signature failed') |
os.Exit(1) |
} else { |
fmt.Println('Verify Signature successful') |
} |
} |