|
@@ -594,77 +594,3 @@ func BoxDecrypt(encrypted []byte, senderPublicKey *[32]byte, recipientPrivateKey
|
|
|
}
|
|
|
return decrypted, nil
|
|
|
}
|
|
|
-
|
|
|
-// DestructMessage - reconstruct original message through chunks
|
|
|
-// func DestructMessage(builtMsg string, priv *rsa.PrivateKey) []byte {
|
|
|
-// var chunks = strings.Split(builtMsg, splitKey)
|
|
|
-// var totalMessage = make([]byte, len(builtMsg))
|
|
|
-// for _, chunk := range chunks {
|
|
|
-// var bytes = decryptWithPrivateKey([]byte(chunk), priv)
|
|
|
-// if bytes == nil {
|
|
|
-// return nil
|
|
|
-// }
|
|
|
-// totalMessage = append(totalMessage, bytes...)
|
|
|
-// }
|
|
|
-// return totalMessage
|
|
|
-// }
|
|
|
-
|
|
|
-// // BuildMessage Build a message for publishing
|
|
|
-// func BuildMessage(originalMessage []byte, pub *rsa.PublicKey) string {
|
|
|
-// chunks := getSliceChunks(originalMessage, 228)
|
|
|
-// var message = ""
|
|
|
-// for i := 0; i < len(chunks); i++ {
|
|
|
-// var encryptedText, encryptErr = encryptWithPublicKey(chunks[i], pub)
|
|
|
-// if encryptErr != nil {
|
|
|
-// fmt.Printf("encrypt err: %v \n", encryptErr)
|
|
|
-// return ""
|
|
|
-// }
|
|
|
-
|
|
|
-// message += string(encryptedText)
|
|
|
-// if i < len(chunks)-1 {
|
|
|
-// message += splitKey
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return message
|
|
|
-// }
|
|
|
-
|
|
|
-// var splitKey = "|o|"
|
|
|
-
|
|
|
-// func getSliceChunks(slice []byte, chunkSize int) [][]byte {
|
|
|
-// var chunks [][]byte
|
|
|
-// for i := 0; i < len(slice); i += chunkSize {
|
|
|
-// lastByte := i + chunkSize
|
|
|
-
|
|
|
-// if lastByte > len(slice) {
|
|
|
-// lastByte = len(slice)
|
|
|
-// }
|
|
|
-
|
|
|
-// chunks = append(chunks, slice[i:lastByte])
|
|
|
-// }
|
|
|
-
|
|
|
-// return chunks
|
|
|
-// }
|
|
|
-
|
|
|
-// // encryptWithPublicKey encrypts data with public key
|
|
|
-// func encryptWithPublicKey(msg []byte, pub *rsa.PublicKey) ([]byte, error) {
|
|
|
-// if pub == nil {
|
|
|
-// return nil, errors.New("invalid public key when decrypting")
|
|
|
-// }
|
|
|
-// hash := sha512.New()
|
|
|
-// ciphertext, err := rsa.EncryptOAEP(hash, crand.Reader, pub, msg, []byte(""))
|
|
|
-// if err != nil {
|
|
|
-// return nil, err
|
|
|
-// }
|
|
|
-
|
|
|
-// return ciphertext, nil
|
|
|
-// }
|
|
|
-
|
|
|
-// // decryptWithPrivateKey decrypts data with private key
|
|
|
-// func decryptWithPrivateKey(ciphertext []byte, priv *rsa.PrivateKey) []byte {
|
|
|
-// hash := sha512.New()
|
|
|
-// plaintext, err := rsa.DecryptOAEP(hash, crand.Reader, priv, ciphertext, []byte(""))
|
|
|
-// if err != nil {
|
|
|
-// return nil
|
|
|
-// }
|
|
|
-// return plaintext
|
|
|
-// }
|