forked from qzind/tray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Salesforce APEX Signing Example | ||
* Returns the signed message to a wired controller | ||
*/ | ||
|
||
// ######################################################### | ||
// # WARNING WARNING WARNING # | ||
// ######################################################### | ||
// # # | ||
// # This file is intended for demonstration purposes # | ||
// # only. # | ||
// # # | ||
// # It is the SOLE responsibility of YOU, the programmer # | ||
// # to prevent against unauthorized access to any signing # | ||
// # functions. # | ||
// # # | ||
// # Organizations that do not protect against un- # | ||
// # authorized signing will be black-listed to prevent # | ||
// # software piracy. # | ||
// # # | ||
// # -QZ Industries, LLC # | ||
// # # | ||
// ######################################################### | ||
|
||
public with sharing class SignMessage { | ||
@AuraEnabled(cacheable = true) | ||
public static String signMessage(String toSign){ | ||
String privateKeyBase64 = '<private-key.pem content without header or footer>'; | ||
|
||
Blob sig = Crypto.sign('RSA-SHA512', | ||
Blob.valueOf(toSign), | ||
EncodingUtil.base64Decode(privateKeyBase64)); | ||
|
||
return EncodingUtil.base64Encode(sig); | ||
} | ||
} | ||
|
||
/** JavaScript - Adjust as needed | ||
import signMessage from '@salesforce/apex/SignMessage.signMessage'; | ||
@wire(signMessage) | ||
qz.security.setSignatureAlgorithm("SHA512"); | ||
qz.security.setSignaturePromise(function(toSign) { | ||
return function (resolve, reject) { | ||
try { | ||
resolve(signMessage({toSign : toSign})); | ||
} catch(err) { | ||
reject(err); | ||
} | ||
} | ||
}); | ||
**/ |