@@ -4,6 +4,7 @@ title: Go
44---
55
66<!-- go run test.go -->
7+
78All the Go code samples can be previewed on https://go.dev/play/
89
910## RSA Decryption
@@ -247,11 +248,39 @@ PSS signatures are supported as well. Here's the phpseclib code to sign somethin
247248``` php
248249use phpseclib3\Crypt\PublicKeyLoader;
249250
250- $key = PublicKeyLoader::load('...')
251+ $key = PublicKeyLoader::load('...');
252+ // the following are implied:
251253 //->withPadding(RSA::SIGNATURE_PSS)
252254 //->withHash('sha256')
253- ->withMGFHash('sha1');
255+ // ->withMGFHash('sha256')
254256
255257echo base64_encode($key->sign('zzz'));
256258```
257- <sup >_ (the actual key is omitted because, for this example, a larger key than the 512-bit key we've been using, is needed)_ </sup >
259+ <sup >_ (the actual key is omitted because, for this example, a larger key than the 512-bit key we've been using, is needed)_ </sup >
260+
261+ To perform PSS signature verification one need only make the following changes to the original script:
262+
263+ ``` go
264+ #
265+ #-----[ FIND ]------------------------------------------
266+ #
267+ signature := " MUE536c4UJSAmycs7V6qFaLMATrKMQA8TYj5xX1+fwHINz3/BafgaRt0ycoD5IxTxaclLWavrGSza4xSBHraEw==" ;
268+ #
269+ #-----[ REPLACE WITH ]----------------------------------
270+ #
271+ signature := " oa7eJv3Ocl4Uh+6M2UBalglijFtCLiYOxRSFafzRt3mp6eNnxsS5GMqvs3nXzRT2KhDlMelssjDJE2wULsnDySld64Wm7+0SYTAQNU1tFVO4JUMpROodT9We24MuLlOssgssr71scolg4NPc+ltCDGu5Y+NRHEwG0vtA7lwLM3c=" ;
272+ #
273+ #-----[ FIND ]------------------------------------------
274+ #
275+ err = rsa.VerifyPKCS1v15 (publicKey, crypto.SHA256 , hashed[:], signatureBytes)
276+ #
277+ #-----[ REPLACE WITH ]----------------------------------
278+ #
279+ opts := &rsa.PSSOptions {
280+ Hash : crypto.SHA256 ,
281+ SaltLength : rsa.PSSSaltLengthEqualsHash , // == crypto.Hash.Size(crypto.SHA256)
282+ }
283+
284+ err = rsa.VerifyPSS (publicKey, crypto.SHA256 , hashed[:], signatureBytes, opts)
285+ ```
286+ Note that, at this time, Go does not let you set the Hash and MGFHash to different values, per https://github.com/golang/go/issues/46233
0 commit comments