
<script src="sodium.js" async></script>
<script>
window.sodium = {
onload: function (sodium) {
try {
let key = 'C06BFAFD06A8158368CF537650C934F3';
let phrase = 'https://xxx.us10.sapanalytics.cloud/sap/fpa/ui/tenants/yyyy';
let h = sodium.crypto_generichash(32, sodium.from_string(key));
key = sodium.from_hex(sodium.to_hex(h));
let nonce = sodium.randombytes_buf(24);
console.log('nonce: ' + sodium.to_hex(nonce));
let encrypt = sodium.crypto_secretbox_easy(phrase, nonce, key)
console.log('ciphertext: ' + sodium.to_hex(encrypt)); }
catch(err) {
console.log(err);
}
}
};
</script>
onCustomWidgetAfterUpdate(changedProperties) {
var that = this;
// try detect runtime settings
if (window.sap && sap.fpa && sap.fpa.ui && sap.fpa.ui.infra) {
if (sap.fpa.ui.infra.common) {
let context = sap.fpa.ui.infra.common.getContext();
appid = context.getAppArgument();
}
if (sap.fpa.ui.infra.service && sap.fpa.ui.infra.service.AjaxHelper) {
tenant_URL = sap.fpa.ui.infra.service.AjaxHelper.getTenantUrl(false); // true for PUBLIC_FQDN
}
if (this._firstConnection === 0) {
let sodiumjs = "http://localhost/SAC/sacsodium/sodium.js";
async function LoadLibs() {
try {
await loadScript(sodiumjs, _shadowRoot);
} catch (e) {
alert(e);
} finally {
if (await sodium.ready.then(sodiumInitialized).catch(sodiumNotInitialized) === tenant_URL) {
loadthis(that, changedProperties);
} else {
console.log("Unauthorized");
alert("Unauthorized");
}
}
}
LoadLibs();
}
}
}
function sodiumInitialized() {
return new Promise(function(resolve, reject) {
try {
let nonce = new Uint8Array(sodium.from_hex('19e6ecf17e866ff0cab830415f98abda9c69b17fb75cb84d'));
let ciphertext = new Uint8Array(sodium.from_hex('a1cb24aff6b92c6cc89026478d093a96fd60b257d5946dbx14464d3c638bcc6f53694191985c1d9839795142069b4ff8f44497d9f40f3d3b448b28ebfd08794b4b1175c2d67e43980cfee4d3b0f33f8f4183d8bb'));
let decrypt = sodium.crypto_secretbox_open_easy(ciphertext, nonce, sodium.from_hex(sodium.to_hex(sodium.crypto_generichash(32, sodium.from_string(appid.appId))))) //Key should be kept secret
resolve(sodium.to_string(decrypt));
} catch (err) {
console.log(err);
resolve('err');
}
});
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
7 | |
7 | |
7 | |
5 | |
5 | |
5 | |
4 | |
4 | |
4 |