-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencodeKeys.as
49 lines (28 loc) · 1.03 KB
/
encodeKeys.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package
{
import com.adobe.crypto.SHA256;
import com.hurlant.util.Hex;
import com.king.encoder.Base58Encoder;
import com.king.encoder.RippleBase58Encoder;
import flame.crypto.RIPEMD160;
import flash.utils.ByteArray;
public class encodeKeys {
public function encodeKeys()
{
}
public function derivePubKeyHash(publicKey:ByteArray):String {
var ripe:RIPEMD160 = new RIPEMD160();
var riped:ByteArray = ripe.computeHash(Hex.toArray(SHA256.hashBytes(publicKey)));
return Hex.fromArray(riped);
}
public function encodePrivateKey(privateKey:String,prefix:String):String {
var encodedPrivateKey:ByteArray = new ByteArray();
encodedPrivateKey.writeBytes(Hex.toArray(prefix));
encodedPrivateKey.writeBytes(Hex.toArray(privateKey));
var checksum:String = SHA256.hashBytes(Hex.toArray(SHA256.hashBytes(encodedPrivateKey))).substr(0,8);
encodedPrivateKey.writeBytes(Hex.toArray(checksum));
encodedPrivateKey.position = 0;
return Base58Encoder.encode(encodedPrivateKey);
}
}
}