I want to encrypt and decrypt my xml file.
I read w3c recommendation about this process.
by some searching
I found npm xml-encryption 1.2.0
https://www.npmjs.com/package/xml-encryption
Has anyone tried it before?
I've installed it but it shows me that error
"require is not defined"
Have you guys any other ways to encrypt xml?
my code
<html>
<head>
<script>
var xmlenc = require('xml-encryption');
var options = {
rsa_pub: fs.readFileSync('./public.pem'),
pem: fs.readFileSync('./public.pem'),
encryptionAlgorithm: 'http://www.w3.org/2001/04/xmlenc#aes256-cbc',
keyEncryptionAlgorithm: 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p',
disallowEncryptionWithInsecureAlgorithm: true,
warnInsecureAlgorithm: true
};
xmlenc.encrypt('content to encrypt', options, function(err, result) {
console.log(result);
})
</script>
</head>
<body>
</body>
</html>
I found the solution here
Client on node: Uncaught ReferenceError: require is not defined
firstly I thought this error is related to the package xml-encryption because I already have installed nodejs
Related
I installed crypto-js like so in my Blazor project
PM> npm install crypto-js
then in the index.html, I used it like so
<script>
... OTHER FUNCTIONS
function encryptMessage(message, key) {
const keyOffSet = 10;
const data = CryptoJS.enc.Utf8.parse(message);
const keyLength = 24
}
</script>
How come that I get an error of
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: CryptoJS is not defined
ReferenceError: CryptoJS is not defined
You need to import CryptoJS by adding CryptoJS CDN. Add the following code before your script tag which contains the logic.
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js" integrity="sha512-E8QSvWZ0eCLGk4km3hxSsNmGWbLtSCSUcewDQPQWZF6pEU8GlT8a5fF32wOl1i8ftdMhssTrF/OhyGWwonTcXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Note: If you still get error, check details of the GET request performed in Dev Tool's Network tab, it would probably have to do with CORS or some other network policy.
I would like try gzip-js. and I make a html file to use function of gzip-js
I went https://www.npmjs.com/package/gzip-js, made "npm i gzip-js", as they suggested, the I got some files anf folders,then I wrote an html file(which is in the folder "\node_modules\gzip-js\lib")
<html>
<script src="gzip.js">
var gzip = require('gzip-js');
var out = gzip.zip('Hello world');
console.log(out);
</script>
<body>
</body>
</html>
I hope it will work as the website show, but I was told "Uncaught ReferenceError: require is not defined at gzip.js:4 at gzip.js:280"
in the console of my browser.
I need to decode h264 data at browser side for that I am using openh264 library build in web Assembly using emscripten.
I have build it successfully and tried to use it in java script to decode the h264 data. But I am getting one error for following line,
var open_decoder = Module.cwrap('open_decoder', 'number', null);
Error is: Uncaught TypeError: Module.cwrap is not a function
If anyone has has build openh264 with emscripten please help me to figure out issue.
Following steps I have used to build openh264 with emscripten.
$ source emsdk_env.sh
$./emsdk activate latest
cd openh264-js-master
make
Note : The code for openh264 has been downloaded from github( ttyridal) and already has make file with emscripten competent.
-s EXTRA_EXPORTED_RUNTIME_METHODS=["cwrap"]
Include above in command line while compiling your source
emcc source.c -s EXPORTED_FUNCTIONS=['_my_add'] -s EXTRA_EXPORTED_RUNTIME_METHODS=["cwrap"]
Probably you are trying to use Module before the Emscripten runtime has been initialized, so Module.cwrap is undefined.
To make sure the runtime is ready, place your code inside of Module.onRuntimeInitialized, as in the following example:
<!doctype html>
<html>
<body>
<script>
var Module = {
onRuntimeInitialized: function() {
my_add = Module.cwrap('my_add', 'number', ['number', 'number'])
alert('1 + 2 = ' + my_add(1, 2));
},
};
</script>
<script async type="text/javascript" src="index.js"></script>
</body>
</html>
See full example in this github repo
At first, I was connecting to Openfire using following script.
const {Client} = require('#xmpp/client')
const client = new Client()
client.start('xmpp://localhost:5222').catch(err => {
console.error('start failed', err)
})
client.handle('authenticate', authenticate => {
return authenticate('gabbar', 'gabbar#123')
})
But it shows me an error 'require is not defined'. so I searched the internet and found that browserify could do my work. so I made the bundle.js file using index.js of my HTML page and included it in the HTML page.
<head>
<meta charset="UTF-8"/>
<title>xmpp.js example</title>
<script src="bundle.js"></script>
<!-- <script src="index.js"></script>-->
</head>
but then I am getting the error
no compatible connection method found
Is anybody can tell any other way of doing it. I tried also same as given in example directory of xmpp.js client package, but that is giving me error like XMPP is not a function. Following is the code which I wrote after looking at example files.
index.js
const {xmpp, xml} =
typeof require === 'undefined' ? window.xmpp : require('#xmpp/client') // For you; require('#xmpp/client')
const {client} = xmpp()
client.start('xmpp://localhost:5222').catch(err => {
console.error('start failed', err)
})
client.handle('authenticate', authenticate => {
return authenticate('gabbar', 'gabbar#123')
})
sample.html
<head>
<meta charset="UTF-8"/>
<title>xmpp.js example</title>
<script src="node_modules/xmpp.js/dist/xmpp.min.js"></script>
<script src="index.js"></script>
</head>
these are the two ways I tried connecting to openfire from the browser side but none of them worked for me. please, can anybody tell me what I am doing wrong or any other possible better way of doing this?
xmpp:// is not supported in the browser. Only ws:// (websockets) is supported in browser. If the server supports websockets, you would do something like:
client.start('ws://domain:port) or client.start('ws://domain:port/xmpp-websockets)
The other option is to use Node not in a browser. Which would be accomplished by running node on it's own without a browser or running that code in the background process of Electron (same as just running node by itself, but you can communicate with the renderer process to interact with a UI)
I'm trying to create a project using elasticsearch.js. I'm following the docs found here.
In the <head> I've loaded:
<script src="js/jquery-1.10.2.js"></script>
<script src="js/elasticsearch.js"></script>
<script src="js/esInit.js"></script>
and in custom.js I have
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
{Host Here}
});
In FB console I see
ReferenceError: require is not defined
var elasticsearch = require('elasticsearch');
I'm reading that require() is not a function of javascript. Very confused.
It looks like you are loading the version that is supposed to be used with Node.js.
There are browser compatible builds available as well: http://www.elasticsearch.org/guide/en/elasticsearch/client/javascript-api/current/browser-builds.html
Yes require is not a default function in javascript. Instead you need to download that js file from "http://requirejs.org/docs/download.html"