Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

You can try this:
***using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

public class Program
{
public static void Main()
{
var key = Encoding.UTF8.GetBytes("SUkbqO2ycDo7QwpR25kfgmC7f8CoyrZy");
var data = Encoding.UTF8.GetBytes("testData");

//Encrypt data
var encrypted = CryptoHelper.EncryptData(data,key);

//Decrypt data
var decrypted = CryptoHelper.DecryptData(encrypted,key);

//Display result
Console.WriteLine(Encoding.UTF8.GetString(decrypted));
}
}

public static class CryptoHelper
{
public static byte[] EncryptData(byte[] data, byte[] key)
{
using (var aesAlg = Aes.Create())
{
aesAlg.Mode = CipherMode.CBC;
using (var encryptor = aesAlg.CreateEncryptor(key, aesAlg.IV))
{
using (var msEncrypt = new MemoryStream())
{
msEncrypt.Write(aesAlg.IV, 0, aesAlg.IV.Length);

using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
csEncrypt.Write(data, 0, data.Length);

return msEncrypt.ToArray();
}
}
}

}

public static byte[] DecryptData(byte[] encrypted, byte[] key)
{
var iv = new byte[16];
Buffer.BlockCopy(encrypted, 0, iv, 0, iv.Length);
using (var aesAlg = Aes.Create())
{
aesAlg.Mode = CipherMode.CBC;
using (var decryptor = aesAlg.CreateDecryptor(key, iv))
{
using (var msDecrypt = new MemoryStream(encrypted, iv.Length, encrypted.Length - iv.Length))
{
using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (var resultStream = new MemoryStream())
{
csDecrypt.CopyTo(resultStream);
return resultStream.ToArray();
}
}
}
}
}
}
}***
4 years ago
Use size_t :

***for (size_t i=0; i < polygon.size(); i++)***
4 years ago
You're looking for Enum.Parse.

***SomeEnum enum = (SomeEnum)Enum.Parse(typeof(SomeEnum), "EnumValue");***
4 years ago
Add to any Class:

***public class Foo
{
public object this[string propertyName]
{
get { return this.GetType().GetProperty(propertyName).GetValue(this, null); }
set { this.GetType().GetProperty(propertyName).SetValue(this, value, null); }
}

public string Bar { get; set; }
}***
Then, you can use as:

***Foo f = new Foo();
// Set
f["Bar"] = "asdf";
// Get
string s = (string)f["Bar"];***
4 years ago
You can also lock your subscribers dictionary to prevent it from being modified whenever its being looped:

***lock (subscribers)
{
foreach (var subscriber in subscribers)
{
//do something
}
}***
4 years ago
You can use the tool bar setNavigationIcon method. Android Doc

***mToolBar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);

mToolBar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handleOnBackPress();
}
});***
4 years ago
You can use the tool bar setNavigationIcon method. Android Doc

***mToolBar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);

mToolBar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
handleOnBackPress();
}
});***
4 years ago
***class AppComponent extends React.Component {

constructor(props) {
super(props);
this.state = {height: props.height};
}

componentWillMount(){
this.setState({height: window.innerHeight + 'px'});
}

render() {
// render your component...
}
}***
Set the props

***AppComponent.propTypes = {
height:React.PropTypes.string
};

AppComponent.defaultProps = {
height:'500px'
};***
viewport height is now available as {this.state.height} in rendering template
4 years ago
Since the original solution was provided for very early version of react, here is an update:

***constructor(props) {
super(props)
this.myRef = React.createRef() // Create a ref object
}

componentDidMount() {
this.myRef.current.scrollTo(0, 0);
}

render() {
return

} // attach the ref property to a dom element***
4 years ago
Here's the best way I found:

***var attribute = event.target.attributes.getNamedItem('data-tag').value;***
Those attributes are stored in a "NamedNodeMap", which you can access easily with the getNamedItem method.
4 years ago
if you don't need to pass arguments to function, just remove () from function like below:

***Details***
but if you want to pass arguments, you should do like below:

*** this.toggle(e,arg1,arg2)}>Details***
4 years ago
The **Express API doc** spells this out pretty clearly.

Additionally this answer gives the steps to create a self-signed certificate.

I have added some comments and a snippet from the **Node.js HTTPS documentation**:

***var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');

// This line is from the Node.js HTTPS documentation.
var options = {
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.cert')
};

// Create a service (the app object is just a callback).
var app = express();

// Create an HTTP service.
http.createServer(app).listen(80);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(443);***
4 years ago