Skip to content

Commit

Permalink
Merge pull request #124 from MingxiaYan/dev
Browse files Browse the repository at this point in the history
Add hex string to Base64 convert
  • Loading branch information
Ashuaidehao authored Aug 2, 2021
2 parents 9da281b + 1b3e52a commit d86be1e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
51 changes: 51 additions & 0 deletions neo3-gui/neo3-gui/ClientApp/src/components/Common/datatrans.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,29 @@ class Datatrans extends React.Component {
});
}
};
base64Trans=()=>{
const { t } = this.props;
var _this = this;
var inhexhash = document
.getElementById("inHexHash")
.value.replace(/(^\s*)|(\s*$)/g, "");
if (inhexhash) {
let _base64 = this.convert.toBase64String(inhexhash);
_this.setState({
outhexhash: _base64,
});
}
var inbasehash = document
.getElementById("inBaseHash")
.value.replace(/(^\s*)|(\s*$)/g, "");
if (inbasehash) {
// let _hash = this.convert.toHexString(inbasehash);
let _hash = Buffer.from(inbasehash, "base64").toString("hex");
_this.setState({
outbasehash: _hash,
});
}
};
// numTrans = () =>{
// var _this = this;
// var inhexnum = document.getElementById("inHexNum").value.replace(/(^\s*)|(\s*$)/g, "");
Expand Down Expand Up @@ -249,6 +272,34 @@ class Datatrans extends React.Component {
</Button>
</p>
</li>
<li>
<Divider className="font-n">
Hex string <SwapOutlined className="small" /> Base 64
</Divider>
<p className="trans-area">
<label>Hex String:</label>
<Input id="inHexHash" type="text" placeholder="63a3989cb4a99571aa00396d3c7155faea4098ba"/>
<label>Base64:</label>
<span id="outString" className="trans-text">
{this.state.outhexhash}
</span>
<br />
</p>
<p className="trans-area">
<label>Base64:</label>
<Input id="inBaseHash" type="text" placeholder="Y6OYnLSplXGqADltPHFV+upAmLo=" />
<label>Hex String:</label>
<span id="outHexString" className="trans-text">
{this.state.outbasehash}
</span>
<br />
</p>
<p className="text-r">
<Button type="primary" onClick={this.base64Trans}>
Transform
</Button>
</p>
</li>
<li>
<Divider className="font-n mt3">
Address <SwapOutlined className="small" /> Script Hash ( little
Expand Down
10 changes: 9 additions & 1 deletion neo3-gui/neo3-gui/ClientApp/src/core/dataConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DataConverter {
var bytes = bs58check.decode(address);
return "0x" + Buffer.from(bytes).toString("hex").slice(2);
}

/**
* direct reverse hexstring,input:'f9df308b7bb380469354062f6b73f9cb0124317b',output:'7b312401cbf9736b2f0654934680b37b8b30dff9'
* @param {string} hexString
Expand All @@ -48,6 +48,14 @@ class DataConverter {
return Buffer.from(hexString, "hex").toString("base64");
}

/**
* input:'Y6OYnLSplXGqADltPHFV+upAmLo=',output:'63a3989cb4a99571aa00396d3c7155faea4098ba'
* @param {*} base64
*/
toHexString(str) {
return Buffer.from(str, "base64").toString("hex");
}

/**
* Encode hex string to utf8 string,input:'7472616e73666572',output:'transfer'
* @param {*} hexString
Expand Down

0 comments on commit d86be1e

Please sign in to comment.